How to configure sendmail properly with PHP on EC2 (no SES)?

7,709

DSN service unavailable sounds relay is not configured properly.

you can edit /etc/mail/sendmail.cf or /etc/sendmail.cf

And change

# "Smart" relay host (may be null)

DS<mailserver_hostname>

This mailserver_hostname should be resolved by your box, otherwise create host entry to point where that is supposed to go.

PS: Personal opinion i would use postfix with sasl relay:

echo “mail.test.com    [email protected]:PASSWORD” > /etc/postfix/saslpass
vi /etc/postfix/main.cf

relayhost = [mail.test.com]:587
smtp_sasl_auth_enable = yes
smtp_use_tls=yes
smtp_sasl_password_maps = hash:/etc/postfix/saslpass
smtp_sasl_security_options = noanonymous

Postmap main.cf / restart postfix

Additional:

Add hostname into your hostfile.. /etc/hosts As you are trying to do sasl relay you can rename your hostname from localhost to something else.

And please check this, Link

Share:
7,709

Related videos on Youtube

Mark Shehata
Author by

Mark Shehata

Updated on September 18, 2022

Comments

  • Mark Shehata
    Mark Shehata over 1 year

    I have been struggling with sendmail for couple of days with no luck. I am trying to setup relay host, after following the answers in this question

    https://stackoverflow.com/questions/10359437/sendmail-how-to-configure-sendmail-on-ubuntu

    I got 'DSN Service unavailable' in the log file. Now I am getting 'Connection refused by [127.0.0.1]'

    What I am trying to do is sending emails from PHP application on the EC2 instance from another smtp server(smtp.mydomain.com) if that possible, what is the required configuration for sendmail and php.ini?

    Thanks

    • ceejayoz
      ceejayoz almost 10 years
      FYI, most of EC2's IP block is blacklisted by major ISPs, which is one of the main reasons SES exists.
  • Mark Shehata
    Mark Shehata almost 10 years
    Thanks tike, I switched to postfix but no receiving "=bounced (host smtp.mydomain.com said: 554 5.7.1 <ubuntu@localhost>: Sender address rejected: Domain MX in loopback network (in reply to RCPT TO command))" - any ideas?
  • user4550002
    user4550002 almost 10 years
    try adding your domain into hostfile.. /etc/hosts
  • Mark Shehata
    Mark Shehata almost 10 years
    It didn't work - my hostname is something like this aws.mydomain.ec2.local - I added it to the hosts file first line <external ip address> aws.mydomain.ec2.local, second line is 172.0.0.1 localhost .. what else should I add?
  • Mark Shehata
    Mark Shehata almost 10 years
    I also tried SES with postifix and I got this "bounced (host email-smtp.us-east-1.amazonaws.com[54.243.69.182] said: 554 Transaction failed: Domain contains illegal character (in reply to end of DATA command))"?!
  • user4550002
    user4550002 almost 10 years
    Where are you trying to relay? Do you have access on that box? Either way, change your hostname to be something simple without - you can change that on /etc /sysconfig/network and tying hostname some.simple.domain your host is strict and rejecting emails