I am trying to configure my Amazon EC2 instance to receive emails with postfix. I tried for hours but I never received an email. If I send email from same server terminal it works. This is working

echo "My message" | mail -s subject noreply@example.com 

But if I try to send email from outside like gmail. I don't receive it. My port 25 is open. I am not receiving any delivery failed messages too. Couldn't find anything related issue from postfix log too. Appriciate if someone can help me to figure out the issue.

Here is my postfix config file.

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = example.com
virtual_alias_maps = hash:/etc/postfix/virtual
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = example.com
relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
alias_maps = hash:/etc/aliases

enter image description here

As Alex suggested the swaks output as bellow.

=== Trying
=== Connected to
<-  220 example.com ESMTP Postfix (Ubuntu)
 -> EHLO ip-172-31-21-89.ap-southeast-2.compute.internal
<-  250-example.com
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-STARTTLS
<-  250-8BITMIME
<-  250 DSN
 -> MAIL FROM:<test@gmail.com>
<-  250 2.1.0 Ok
 -> RCPT TO:<noreply@example.com>
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with <CR><LF>.<CR><LF>
 -> Date: Sat, 12 Mar 2016 23:08:43 +1100
 -> To: noreply@example.com
 -> From: test@gmail.com
 -> Subject: Test
 -> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
 -> This is a test mailing
 -> .
<-  250 2.0.0 Ok: queued as E44EE642AD
 -> QUIT
<-  221 2.0.0 Bye

And I have received that email. Then again I tried sending an email form my Gmail. Unfortunately it failed. And when I try to check my noreply@example.com email from here. It says "Bad" http://verify-email.org/

  • Install swaks 'yum install swaks/apt-get install swaks' and then execute 'echo "Hello world" | swaks -s ec2.instance.ip --to user@your.domain.com --from test@gmail.com --h-Subject "Test" --body -' from any other linux box. Not from the server itself. Add the output to the question. – ALex_hha Mar 12 '16 at 9:01

Your MX record points to the name smtp.example.com, but this name doesn't have any address records.

$ host example.com
example.com has address
example.com mail is handled by 10 smtp.example.com.

$ host smtp.example.com
Host smtp.example.com not found: 3(NXDOMAIN)

Mail for your domain is therefore undeliverable.

  • Yes that was the problem. I have updated MX records. Thanks everyone. – Prasad Rajapaksha Mar 12 '16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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