Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone teach me how to configure a centos instance to send mails.

My intention is to send mails from a bash script based on some signals and alerts to a build user. I don’t intend to use it as a mass mailing machine.

share|improve this question
up vote 10 down vote accepted

This is a perfect fit for Amazon's Simple Notification Service. The service (also known as SNS) is simple to use from a bash script, free (for the first 100,000 messages, less than 1gb in total), and the notifications are immediate.

The setup for SNS looks like this: enter image description here
From:SNS Documentation

It looks like a lot of trouble to send eMail, however, Amazon's EC2 environment is highly restrictive when it comes to sending eMail. Many have tried to use EC2 as a spam platform, so Amazon has been thorough in blocking SMTP (eMail) traffic, except as prescribed by Amazon. You can't just open up a port on the Amazon security group to bypass Amazon's blocks.

Amazon does have a general eMail facility one can use from within EC2. It is called, Amazon Simple Email Service (SES). That will not work well for you, as it is designed for bulk eMail. So, SES's pricing, exception handling and messaging won't fit well with your application as I imagine it.

SNS, on the other hand works great for this. It includes an initial eMail to the recipients (your build users) asking if they want to receive future messages of the topic; they are given an option to opt out, and must reply to receive further.

The setup process (shown in blocks above) is all easily doable from Amazon's AWS Management Console. (Your question implies you that you already have an AWS EC2 account needed for this.) Once setup, your command from bash would be similar to:

$PROMPT> sns-publish arn:aws:sns:us-east-1:365928882516:Foo --message "Hello, world!"

The example above is done using the Command Line Interface available for SNS. This Command Line Interface is available at: (Amazon Simple Notification Service Command Line Interface Tool), and it's documentation is here: (Amazon Simple Notification Service Command Line Interface Documentation). Set it up first though, as described above.

It'll be gotcha-free in setting up, and solid as a rock in operation.

share|improve this answer
Very helpful. Was a bit tricky getting SNS set up initially. I had to include the region explicitly otherwise it couldn't find the resource despite the region being a part of the resource identifier. – g . Nov 4 '11 at 12:33

If you use your own mail server (on Centos), remember to remove the EC2 email sending limit!

share|improve this answer

Note that in the latest version of the CLI, which now combines AWS services into one executable, the syntax has changed slightly. The above command would now be:

$PROMPT> aws sns publish --topic-arn arn:aws:sns:us-east-1:365928882516:Foo --message "Hello, world!"

Also note that if you haven't set the AWS_DEFAULT_REGION environment variable (this is not set by default on AMAZON Linux AMIs, for example), you'll need to specify the region:

$PROMPT> aws --region us-east-1 sns publish --topic-arn arn:aws:sns:us-east-1:365928882516:Foo --message "Hello, world!"

Source: Amazon's unified CLI documentation.

share|improve this answer

I know it's old topic, but today you can use SES as sendmail

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.