Home > UNIX > Use MUTT to send email attachments and specify from address

Use MUTT to send email attachments and specify from address

Recently I had to change the outgoing email program used on my AIX boxes. Previously mailx was used along with uuencode. This had become a problem due to some webmail sites and mail clients being unable to decipher uuencoded attachments. To overcome this I installed MUTT from the AIX Toolbox for LINUX Applications cd.  MUTT will send the attachments using MIME.

 The requirements from the programmers that determined which switches I used were as follows:

  • Have to be able to script the command.
  • Ability to set the ‘from’ and ‘to’ email address fields
  • Ability to set the subject
  • Ability to attach pdf documents
  • Ability to put a standard text file into the email body

Here is the command I used:

 mutt -e ‘set from=fromaddress@test.com’ -s ‘subject’ -a file.pdf toaddress@test.com < body.txt

 Explanation of options:

 mutt : The mail client being used to send the email.

 -e : Specify a command, this must be in quotes, in this case we are setting the from email address variable to fromaddress@test.com

 -s : subject of the email, must be in quotes if there will be spaces or special characters

 -a : attachment, specify the file to be attached in mime format. In this case a pdf file in the current working directory, can be a full path.

 The to email address must be specified at the end of the command with no switch options. In this case I am sending the email to toaddress@test.com

 < : Put the contents of a file into the message body. This can be a file that has something standard we want in all emails. Could also use echo to put something in on the fly, or use /dev/null to have a blank body. There HAS to be something redirected to the body or it will not send.

 

Advertisements
Categories: UNIX
  1. April 6, 2010 at 18:59

    I found Shtrudel M@il – a free secured webmail with tons of good features and great availability of user names and email addresses. Also, you can park your domain on Shtrudel M@il and use it for your business. Shtrudel Mail

  2. dan
    July 7, 2013 at 15:39

    Actually it’s rather this (the -a part must be at the last part):
    mutt -e ‘set from=fromaddress@test.com’ -s ‘subject’ toaddress@test.com -a file.pdf < body.txt

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: