I am trying to send mail from a VM instance on Google Cloud which I have recently set up and migrated everything over from my old server.
However, I have found out Google Cloud does not allow sending mail via port 25, so I am trying to send via ports 465 or 587, but mail is not getting through, it is ending up as deferred in the mail queue.
How do I send mail from Google cloud?
According to this: https://cloud.google.com/compute/docs/tutorials/sending-mail#choosing_an_email_service_to_use
...ports 465 and 587 are open.
Just a little more information, I have tried sending via the webmail on Plesk, and via Thunderbird. Both ways are accepting the username and password, and shows the email as sent. But is then stuck in the queue.
This is in: /var/log/maillog
Jul 22 16:11:19 104-155-103-102 postfix/cleanup[2128]: 60E50220AB66: message-id=<0044ead7-f1c2-9665-8fca-ea50c7673c06@email_address.com>
Jul 22 16:11:19 104-155-103-102 spf[2131]: Starting the spf filter...
Jul 22 16:11:19 104-155-103-102 spf[2131]: SPF status: PASS
Jul 22 16:11:19 104-155-103-102 psa-pc-remote[31599]: PASS during call 'spf' handler
Jul 22 16:11:19 104-155-103-102 check-quota[2132]: Starting the check-quota filter...
Jul 22 16:11:19 104-155-103-102 psa-pc-remote[31599]: SKIP during call 'check-quota' handler
Jul 22 16:11:19 104-155-103-102 postfix/qmgr[723]: 60E50220AB66: from=<enquiries@email_address.com>, size=4190, nrcpt=1 (queue active)
Jul 22 16:11:19 104-155-103-102 postfix/error[2134]: 60E50220AB66: to=<to_email_address@live.co.uk>, relay=none, delay=0.58, delays=0.57/0.01/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to eur.olc.protection.outlook.com[104.47.22.161]:25: Connection timed out)
Jul 22 16:11:19 104-155-103-102 postfix/smtpd[2123]: disconnect from unknown[112.30.25.225] ehlo=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=6
Thank you
UPDATE
I still have access to my old server which allowed mail sending on all ports inc port 25. This server was still set up with Plesk and the domain, along with all my enquiries@mydomain.com
Prior to posting the original post, I had already tried the following:
DNS Records
mydomain.com -- MX (10) -- mail.mydomain.com
mail.mydomain.com -- A -- old.server.ip.address
This obviously worded to be able to use the old server as the email server and bypassed the new server when sending emails using a desktop app like Thunderbird. However, I also have PHP scripts to send emails to members, so I needed to get the relayhost working.
I tried this below, along with many other variants over many days, however it would not work, hence why I made this post. I am still not sure why it was showing "relay=none" and was showing port 25 in the maillog.
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = static:enquiries@mydomain.com:mypassword
relayhost = [old.server.ip.address]:465
#also tried port 587
This kept timing out as shown above in the maillog. I then decided to try using gmail as an smtp server, which didnt work at first:
smtp_sasl_password_maps = static:mygmail@gmail.com:mypassword
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
relayhost = [smtp.gmail.com]:465
However, last night I added the first 3 lines shown, then it worked great (except the "from" email address was showing as my personal email address, but at least the emails were sending):
smtp_always_send_ehlo = yes
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
smtp_sasl_password_maps = static:mygmail@gmail.com:mypassword
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
relayhost = [smtp.gmail.com]:465
I then decided to try my old server again, and replaced the ip address for the server with "mail.mydomain.com".
smtp_sasl_password_maps = static:enquiries@mydomain.com:mypassword
relayhost = [mail.mydomain.com]:465
I have since replaced the static password to:
#smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
And it is now working fine. I will reflect this in an answer below.
As someone who has never had to set up a SMTP server, ports etc, I was unaware that mail boxes only usually listen for new mail on port 25, and was unsure what this meant, hence my confusion.