How to send email with my CentOS server?
/bin/mail -s "Enter Subject Line here" -a
/home/.../whateverFileYouWantAttached
"you@YourEmailAddress"
< /home/me/textBody.letter
try above command :)
Simple answer:
Set up sendmail. It will depend on your distribution but this isn't difficult at all. If you have any specific questions, ask away.
Complicated answer:
If you're asking this, you probably should not just jump the gun and setup sendmail justtt yet.
You'll need to take a few things into consideration:
Does your ISP allow you to send e-mail? You might be on non-server IP range and therefore, many e-mail providers will block your outright.
What address will you use as your from address? Are you authorized to send from this address (SPF, DomainKeys, etc)? If not, your messages might be detected as spam by e-mail providers---and rightfully so.
Last, but certainly not least: Do you really need to use your own SMTP service? Any reason why using your ISP's is not good enough?
Back in the days, setting up an SMTP server wasn't a big deal. Nowadays, the setup may be easier but setting it up so that it actually gets messages to people's mailboxes, is a challenge.
I can confirm that none of the above suggestions are working on my CentOS system at home either - not a single one. Which is annoying!
Then I tried the same on a fresh Amazon instance running CentOS 6.4, and even with the default configuration, I can send mail without problems. All I had to do was
yum install mailx
after which sending mail as described above works like a charm. Installing complications like sendmail are NOT necessary for what Jakub is trying to do.
It must be some configuration with my ISP, since I haven't got a configurable firewall at my end here.
You need to do the following:
sudo yum install postfix telnet mailx
sudo /etc/init.d/postfix start
sudo vi /etc/postfix/main.cf
-
Change
mydestination = mydomain.com, localhost.mydomain.com, localhost
to
mydestination = localhost.mydomain.com, localhost
Test using the following from the command line
- mail [email protected] Subject:
- Test email from demoslice.com Test
- body of the email.
.
No. 4 - there is just a full stop to complete the body of the email. You now should have mail.
The above will get you a working MTA (Mail Transfer Agent). Some resources which will help you with a more advanced setup can be found at slicehost's articles on email setup for CentOS (scroll down to the CentOS and Email section). You should really consider setting the following correctly: hostname, RDNS (Reverse DNS) and SPF (Sender Policy Framework) records with your DNS provider.
Have you modified your /etc/mail.rc to set the smtp address?