Search code examples
phpamazon-web-servicessendmaillamppostfix-mta

Is anybody able to send mails to gmail through AWS LAMP server using postfix, sendmail


I am using php mail function to send mails to gmail,yahoo accounts. I have a AWS LAMP instance, i have installed postfix and sendmail. I went through many forums infinite number of forums, still not able to send mails. After too many changes i was able to see Message accepted for delivery, but after some time got the same message. stat=Deferred: Connection timed out with mta7.am0.yahoodns.net. stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.

Just i am wondering is anyone able to send mails using the same scenario.


Solution

  • TLDR: Sending email is hard. Don't attempt final delivery yourself. Use AWS SES or another ESP.

    As AWS is aware that spammers have, and will, try to send their mail from anywhere by any means, AWS explicitly prevents EC2 Instances from being able to send email without some effort. It is not in your best interest as a sender to attempt to send email directly, unless you understand very well the various mechanisms in place to securely send email, accurately identify yourself as a legitimate sender, and gain reputation on your EIP with ISPs. Primarily, AWS intends for you to use SES to send email outside your VPC.

    I can't emphasize enough that businesses small and large choose to send their mail through a third party (an ESP, or Email Service Provider, like AWS SES) in order to resolve the many, many issues that will come up when attempting to do it all yourself. The various acronyms involved, all of which require their own research and understanding from various RFC's include: SPF, DKIM, and DMARC; there is also the regular maintenance required in monitoring whether or not your IP is currently, or in the future, blacklisted by the various RBL's that monitor Spam Traps; and, of course, list hygiene, or scrubbing your list for bounces (not doing these is a guaranteed path to staying in the spam folder, even if you finally succeed in sending email out port 25). Let an ESP do some of this for you.