Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm having trouble getting sendmail to send out emails from my AWS EC2 machine.

I'm using the following command to send an email:

sendmail -vt < mail.txt

The mail.txt file has the following content (edited for security):

To: locksleyu@yahoo.com
Subject: Put a subject here
From: to_whoever@example.org

Message body

When I run sendmail it looks like things are working:

>>> MAIL From:<ec2-user@XXX.us-west-2.compute.internal> SIZE=128
250 2.1.0 <ec2-user@XXX.us-west-2.compute.internal>... Sender ok
>>> RCPT To:<locksleyu@yahoo.com>
>>> DATA
250 2.1.5 <locksleyu@yahoo.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 s0FLLsxw009758 Message accepted for delivery
locksleyu@yahoo.com... Sent (s0FLLsxw009758 Message accepted for delivery)

However I never get the email on my yahoo account. Next I checked /var/log/messages and it said I have new mail in "/var/spool/mail/ec2-user". Here is what I saw in that file:

 ----- The following addresses had permanent fatal errors -----
 (reason: 553 #5.1.8 Domain of sender address <ec2-user@XXX.us-west-2.compute.internal> does not exist)

 ----- Transcript of session follows -----
... while talking to smtp02.yahoo.com.:
>>> MAIL From:<ec2-user@XXX.us-west-2.compute.internal> SIZE=669
<<< 553 #5.1.8 Domain of sender address <ec2-user@XXX.us-west-2.compute.internal> does not exist
501 5.6.0 Data format error

Can someone tell me what configuration is needed to make this work? The XXX above is my ip-XXX-YYY-ZZZ-AAA address which corresponds to my EC2 machine.

I did some searching around for solutions but none of those I found have worked for me so far.

share|improve this question
Yahoo has stringent anti-spam requirements if you desire to deliver directly to their users. Among them are reverse DNS lookup. If this is the problem, another tactic can be to deliver mail to a recognized server, such as your company or customer's mail server, and have that forward to Yahoo. The intermediate mail server would simply have to accept mail from the EC2 machine, after that it should know what to do. –  kmarsh Jan 15 '14 at 22:41

2 Answers 2

up vote 1 down vote accepted
 ----- Transcript of session follows -----
... while talking to smtp02.yahoo.com.:
>>> MAIL From:<ec2-user@XXX.us-west-2.compute.internal> SIZE=669
<<< 553 #5.1.8 Domain of sender address <ec2-user@XXX.us-west-2.compute.internal> does not exist

Explicitly set envelope sender address using sendmail -f command line options


Make your sendmail use "this host email name" ($j) with public MX or A DNS records.


Make your sendmail masquearde as another host for email purposes

share|improve this answer
Take that last step and make sendmail use the server's actual external DNS hostname, not its internal DNS hostname, as it is using now. EC2 has a fake internal ".internal" TLD for internal host resolution. Changing the hostname from "xxx.us-west-2.compute.internal" to "xxx.us-west-2.compute.amazonaws.com" (the answer you get if you nslookup your EC2 machine's IP address from outside EC2) and using this to configure sendmail's hostname should also work. –  Michael - sqlbot Jan 16 '14 at 2:38
Thanks (to both Michael - sqlbot and Andrzej), I think is what what I need to do. Can you confirm the configuration required to masquerade? I am trying MASQUERADE_AS(`us-west-2.compute.amazonaws.com')dml in the /etc/mail/sendmail.mc file, and restarting, but it doesn't seem to be working. I still see .compute.internal in the log. –  Locksleyu Jan 16 '14 at 13:15
I tried masquerade_envelope and masquerade_entire_domain but those didn't help either. I finally got it to work by adding -f to sendmail with any address. However I don't understand why is is required. If someone can explain why this matters I'd appreciate it. I am already setting the 'From:' header, and masquerade_envelope also should be doing something similar if I understand correctly. –  Locksleyu Jan 16 '14 at 13:36
MASQUERADE_AS(...) and FEATURE(masquerade_envelope) [and optionally FEATURE(allmasquerade)] should fix the problem. You may use sendmail -Am -vt < mail.txt as root to test it. –  Andrzej A. Filip Jan 16 '14 at 13:43
I was still seeing strange behavior with command line sendmail(), but when I switched to PHP's mail() function (which uses sendmail()), it worked great. Not sure why but I'm happy! –  Locksleyu Jan 16 '14 at 14:19

Large swaths of the EC2 address space are blacklisted by several email providers. If you need to send email from your instance, you'll either need to relay out through a non-EC2 host or else use AWS's SES service to send email.

Personally, I use SES, as it's very easy to integrate with your MTA, and prices are very low (or free) for all but the largest email volumes.

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.