问题
I have a simple website which runs with Joomla!, and it has a contact form from where the visitor can send a message to me. This message is sent by e-mail using the sendmail
service.
The website machine is running inside Google Compute Engine, and by default I can't send e-mails from it (that's a restriction imposed by Google). To achieve the goal of sending e-mails, a 3rd-party service is needed, such as SendGrid.
I created a free account on SendGrid using the Google Cloud partner program, validated my user and so on. The account is properly provisioned.
I configured my sendmail
service to use SendGrid to deliver the e-mails, according to this tutorial. Everything seems to be ok, but... no message is delivered at all.
My mail log at /var/log/mail.log
shows:
Jan 21 16:22:10 web-hosting sm-mta[16350]: t0JHWaec027559: to=<my@email.com>, delay=1+22:49:34, xdelay=00:00:00, mailer=relay, pri=23251559, re
lay=smtp.sendgrid.net., dsn=4.0.0, stat=Deferred: Connection timed out with smtp.sendgrid.net.
According to Google, my machine can't use the ports 25
, 465
and 587
, so I changed the configuration to use the port 2525
in the sendmail.mc
file. Nothing changed.
Any hints? My machine is running Ubuntu 14.04LTS.
回答1:
Ok, I found the problem.
My original /etc/mail/sendmail.mc
file don't have the #dnl define(‘SMART_HOST’, ‘smtp.your.provider’)dnl
line, so I didn't know exactly where to put the configuration (source):
define(`SMART_HOST', `smtp.sendgrid.net')dnl
FEATURE(`access_db')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 2525')dnl
(Note: for Google Compute Engine machines, you need to use the 2525 port instead of the default 587)
The thing is, you can't put it at the end of the file. The configuration started working when I put it just after the "DO NOT TOUCH HERE" section:
dnl # Items controlled by /etc/mail/sendmail.conf - DO NOT TOUCH HERE
...
DAEMON_OPTIONS(`Family=inet, Name=MSP-v4, Port=submission, M=Ea, Addr=127.0.0.1')dnl
dnl # SendGrid code here
来源:https://stackoverflow.com/questions/28072278/how-to-use-sendmail-with-sendgrid-from-google-compute-engine