/ Published in: Bash
Expand |
Embed | Plain Text
echo "email body" | mail -s "subject" emailname@host
Comments
Subscribe to comments
You need to login to post a comment.
yuconner on 08/25/06
9 people have marked this snippet as a favorite
mate
willcodeforfood
Samga
sjaq
alexxx
Leech
cbrant
noone453
ringo380
echo "email body" | mail -s "subject" emailname@host
Subscribe to comments
You need to login to post a comment.
Hi,
this had me perlexed for days. mail doesn't work, or give an error (unless I do it through my hosting company). Why? Because mail does not allow you to specify an smtp sever to relay your mail through, and unless you can go through the the grief of setting up you machine as a bonafide mail server, you're attempts will get rejected by the recepient as spam (without informing you).
Solution: use nail, which does allow you to specify an smtp server to relay your mail through. You don't need to go through any sendmail config files.
http://forums.fedoraforum.org/showthread.php?t=143690 "Rupert Pupkin" The problem with the standard 'mail' command is that it assumes that the machine it is running on is a full-fledged SMTP server. So unless you've configured your machine to be a bonafide mail server (or to act as an SMTP relay), then your mail will not go anywhere outside your machine (i.e. it will only work for addresses local to your machine, e.g. some_user@localhost). There is no way to specify an external SMTP server (like your ISP's) to use with the 'mail' command. That's why you're getting a dead letter.
If you want a command-line mailer that does support using an external SMTP server, then get nail from Fedora Extras. Nail supports specifying an external SMTP server. You can do this on a per-mail basis, like this:
nail -r "[email protected]" -s "Some subject" -S smtp=some.smtp.server [email protected] < msg.txt
or you can permanently set the SMTP server in your ~/.mailrc file (or /etc/nail.rc if you want to set it system-wide), which removes the need for using the "-S smtp=..." option on the command-line:
set smtp=some.smtp.server
See the nail man page for more details. In my opinion, no one should be using 'mail' anymore, nail is vastly superior."