Configuring Sendmail to send mail from command line
It can be very frustrating to try to send mail through the command line using sendmail. Although sendmail is preinstalled on most linux system, it is configured not to deliver any mail to the outside (probably to prevent spamming).
Configuring it is very simple. First you'll need the sendmail-cf package. Install it using yum:
Edit the file /etc/mail/sendmail.mc and add the following lines. Make sure you set your mail server domain name where it's bolded:
MASQUERADE_DOMAIN(yourdomain.com)dnl
In the same file /etc/mail/sendmail.mc remove the "dnl" from the beginning of the lines so it will look like this:
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
Save the file and compile it using m4:
Send Sendmail a -HUP signal using kill or simply restart the daemon for the configuration changes to take effect:
Testing your configuration using sendmail
And that's it! you're done. Just send yourself a test email to make sure it is really working:
Where the contents of the mail.txt file are:
To: you@somewhere.com
Subject: The subject of the message
From: whatever@somewhere.com
Body of message goes here
Testing your configuration using mutt
You can also use mutt to test, which is a bit simpler (and you can also add the -a parameter for file attachment):
Anonymous:
Simple and effective! Thanks for this...
adambengur:
If you get the following error:
553 5.3.5 localhost.localdomain. config error: mail loops back to me (MX problem?)
Add the following line to the /etc/mail/sendmail.mc, compile with m4 and restart sendmail:
MODIFY_MAILER_FLAGS(`relay',`+k')
Anonymous:
Thanks, just what I was looking forward.
Had a brain freeze when for testing sendmail - I have been using postfix for so long. :)