TransWikia.com

Send mail via port 465 or 587 on Google Cloud VM / Postfix

Server Fault Asked by SW_Cali on November 27, 2021

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=<[email protected]>, 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 [email protected]

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:[email protected]: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:[email protected]: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:[email protected]: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:[email protected]: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.

2 Answers

Since posting my question above, I have managed to get the mail working, so I will post my solution below to hopefully help others.

I know it has all be covered before, as I found it all by searching, however bits were missing or didnt work for me so I have put it all together below.

This is what got my email working, in two different ways, via gmail and also a different smtp server.

I think what was making it fail before was because I used the smtp servers ip address:

relayhost = [123.456.654.321]:465

rather than the domain:

relayhost = [smtp.myrelayhost.com]:465

But that may have just been a coincidence.

I also added the following just before it got working:

smtp_always_send_ehlo = yes
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
#all necessary for port 465?

So the final options which got this working are:

smtp_always_send_ehlo = yes
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = static:[email protected]:mypassword
relayhost = [smtp.myrelayhost.com]:465

OR

smtp_always_send_ehlo = yes
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = static:[email protected]:mypassword
relayhost = [smtp.gmail.com]:465

I also changed the static username and password, and included it in saslpasswd instead:

smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd

in /etc/postfix/saslpasswd:

[smtp.myrelayhost.com]:465 [email protected]:mypassword

Then ran this in SSH (I think to save saslpasswd as a .db file...?)

# postmap /etc/postfix/saslpasswd

Then restarted postfix:

# /etc/init.d/postfix restart

Answered by SW_Cali on November 27, 2021

Foreign SMTP servers are not going to be listening on ports 465 or 587 for general mail; they will only listen on port 25. Ports 465 and 587 are for secure relaying, and systems will accept mail on those ports only for authenticated users. Thus you would need an external mail service to relay your messages properly.

Answered by CB_Ron on November 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP