But today I had to send emails with attachments and mailx has no built in support for them. If you know something about emails standards, you could easily figure out how to do it. Google searches about the topic are full of examples of sending properly formatted mails with mailx, where properly means uuencoding the attachments, concatenating them with the mail message and then send them all piped to mailx. Some examples you can find are even easily scriptable. Reinventing the wheel, more often than not, is not a mean for progress so I decided to go with mutt, a powerful program I always neglected favoring mailx.
mutt has a similar syntax and has built in support for attachments. Its configuration file is a powerful tool to create different sending profiles in which you can, for example:
- setting user mail identity
- modify mail headers
- write and attach hooks to mail events
for i in addresses ; do
cat user-message-file | mutt -s subject -a attachment-1 ... attachment-n -- $i
done
cat user-message-file | mutt -s subject -a attachment-1 ... attachment-n -- $i
done
Please note that the the option -- is necessary only for separating the addresses from a list of multiple attachments. In the case of just one attachment the line above reduces to:
for i in addresses ; do
cat user-message-file | mutt -s subject -a attachment $i
done
cat user-message-file | mutt -s subject -a attachment $i
done
I also had to modify some header and both mutt and muttrc man pages are well written and easy to search. The content of my (first) ~/.muttrc configuration file is:
set realname="myname"
set from=myuser@mydomain.com
set use_from=yes
set use_envelope_from=yes
set from=myuser@mydomain.com
set use_from=yes
set use_envelope_from=yes
my_hdr Reply-To: anotheraddress@mydomain.com
This way I told mutt:
- to set my name
- to set the From: header
- to use the From: header
- to force sendmail to use the same address from the From: header as the envelope address
- to use a Reply-To: header
No comments:
Post a Comment