Using mutt from command line or script

Hello,
I am attempting to send emails from AIX 5.2 using either the mailx command or mutt. When I use mutt:

  mutt -a jim.txt -s "Test Email" me@mydomain.com

It sends the attachment, but it forces me into the interactive menu.

 When I use mailx:
 cat data.txt | uuencode data2.txt | mailx -s "Test" myemail@mydomain.com

It sends the attachment, but carriage returns for each line are striped and it comes as all one line.

I eventually want to do this with a script, but not sure how to get this working.  I have done some searching, but can't seem to find anything helpful.  Can you provide me with some links to scripts that I could look at?  Thank you.

Windows clients expect \r\n in text files, UNIX uses \n. Translate the text file before sending.

sed 's/$/\r/' unix.txt > win.txt

Hi Corona688,
The file is being written out by a Cobol program that places a Carriage Return, Line Feed at the end of each line. The uuencode seems to be removing the carriage return. The mail client mutt leaves it intact. Do you know of a way to use mutt at the command line without it bringing up the interactive menu? Thank you.

uuencode is for encoding binary files and really ought to encode what you have verbatim. If carriage returns are missing on the other end, I suspect they're missing on the input too, for whatever reason.

Have you tried adding carriage returns?

Hi Corona688,
I did some more searching and found that if I code the line this way:

 mutt -a jim.txt -s "Test Email" me@mydomain.com < /dev/null

It sends the attachment with the carriage return/line feed. Now I have to figure out how to get the from address in there as it sends it with out one. Any Idea's? Thank you for your help.

Try this (works using Korn shell on Solaris, your options my vary):

#!/bin/ksh

# Convert line feeds from the source and write to attach.out.
unix2dos -437 -ascii data.txt attach.out

# Now uuencode attach.out and call it data.txt for the attachment name.
(print "Please review the attached file";uuencode attach.out data.txt) | mailx -s "Test" myemail@mydomain.com

exit 0

Note that the "attach.out" filename can be omitted from the unix2dos command, where then the original file will be overwritten with the converted version. This example preserves the original data.txt file.

Hi Gary_W,
Thank you for the script, but I don't have unix2dos.

It can be implemented as a script. I just found this which may be of help:

P.S. A little googling found other sed scripts too which do the job.

I told you hours ago:

sed 's/$/\r/' unix.txt > win.txt

Have you tried adding carriage returns yet?

And my response earlier was that the file already has a carriage return and line feed. I also found that mutt works with the command I showed earlier leaving the carriage return/line feeds in place so I only need to figure out how to place the "from" address in the email so that when it is received it has a "from" address. Thank you.

---------- Post updated 02-28-12 at 07:07 AM ---------- Previous update was 02-27-12 at 09:01 PM ----------

Hello all,
I was able to resolve my issue by setting a default email address in the Muttrc config file. This works for my purposes as I will be the only one sending email from this system. For others they will probably want to set up a person config file. The following command is what I end ed up with.

mutt -a pnc_data.txt -i mutt_body.txt -s "Test Email" my@somedomain.com < /dev/null
Thank you for your help.

And my response earlier was that uuencode is a method of encoding binary files so ought to translate verbatim. If you aren't willing to even try...