Configuring sendmail for use of Gmail with SMTP on digital ocean

gmailsendmailsmtp

I followed these instructions, and I have this running from the command line. I run a test from the command line like so:

echo "Just testing my sendmail gmail relay" \
| mail -s "Sendmail gmail Relay" my-email@example.com

There is a delay, but it does eventually send the email…

When I call mail() from php, it's timing out or dying with a "504 Gateway Time-out" error.

In the article it says "If you will experience substitutional delays after executing the above command to most likely cause is that you have not configured your host with FQDN. Check your logs for a warning:"

I don't find anything in the logs. I have restarted the server, but can't think of anything else to try… I believe the hosts are configured properly with:

127.0.1.1 server-name
127.0.0.1 localhost

I'm not sure what else to try at this point….

Any tips ideas or advice?

Best Answer

Neither server-name nor localhost are fully qualified; a fully qualified hostname instead looks like server-name.example.org or localhost.localdomain. sendmail will show what domain names it is using via the command

sendmail -d0.1 < /dev/null

It may also be helpful to find the mail logs on your system (this depends on the syslog daemon configuration) and see exactly which sendmail process (or processes) are complaining about what, as I do not know whether whatever your PHP code is is going through sendmail like your command line example is (sendmail -> MSA -> MTA) or whether it is submitting directly to the MTA via SMTP.

Sendmail depends heavily on properly configured DNS; you might try to kluge around it via

    FEATURE(`nocanonify', `canonify_hosts')
    define(`confDIRECT_SUBMISSION_MODIFIERS', `C')

in the submit.mc configuration, though this could break things (and without the logs I don't know if that is a source of the issue). You may also need to setup masquerade so that the addresses are properly standardized before being lobbed off to gmail.

Yet another option would be instead to send mail out via something like ssmtp.