SOLVED Can't send email to Gmail

Joined
Mar 2, 2019
Messages
4
Hi guys.

I am having issues setting up email notifications using my gmail account.

The error i get is this: [EFAULT] Failed to send email: Connection unexpectedly closed

What i have set up right now:

FreeNAS-11.2-U2.1
Root user config -> mymail@gmail.com
From E-mail -> mymail@gmail.com
Outgoing Mail Server -> smtp.gmail.com
Mail Server Port -> 587
Security - > TLS
SMTP Authentication -> checked
Username -> mymail@gmail.com
Password -> 2step auth password for mymail@gmail.com

DNS and Default Gateway are filled in correctly.
I have access to internet.
I can resolve and ping smtp.gmail.com
I can "telnet smtp.gmail.com 587", send EHLO and send STARTTLS, after that i quickly get "Connection closed by foreign host", but as far as i know this is how it is supposed to be with telnet.

Using the exact same settings i am able to send mail from both my Nextcloud instance and my Mikrotik router just fine meaning i probably have set-up my google account correctly (enabled 2-step auth, created a new password)

I am honestly lost what i could've done wrong, any help or ideas would be appreciated.
 

Heracles

Wizard
Joined
Feb 2, 2018
Messages
1,401
Hi ImmortalBrain,

For the password, you need an App Password from gmail. To get one, you need to log in your Google account and generate this App-specific password. Once you got it, you use it for your e-mail setup. Because you said that you are good with Nextcloud, you probably got that one right. Just be sure that Google allows you to re-use a code from one App to another.

You also mentioned port 587 and TLS. Because I use a local mail server, I never used TLS in my setup for that. Just know that there are 2 ways of doing TLS for SMTP. First is to handshake TLS first and once done, you start your SMTP handshake on top of it. This mode is like HTTPS and is usually performed on port 465.

The other mode is STARTTLS. You start by handshaking SMTP and the first command you do after that is to handshake TLS using the STARTTLS command. This is what is usually done over port 587. If your setup is trying to handshake TLS first and the server is waiting for SMTP first, the two will not be able to communicate.

From your telnet capture, we see that indeed, Google is expecting SMTP and STARTTLS. So a step for you would be to sniff your FreeNAS trying to reach Google and see if it is trying to handshake TLS first or not. Another option would be to see if Google accepts SMTP on port 465 and try that one.

Good luck,
 

diedrichg

Wizard
Joined
Dec 4, 2012
Messages
1,319
Literally done everything exactly like in the linked thread, no go =(

I've also tried that with a separate google accoun't that has 2-step auth disabled while using "normal" gmail password, same error. Allowing "Less-secure apps" didn't help either.
Router blocking? Sophos or pfSense blocking?
 
Joined
Mar 2, 2019
Messages
4
Router blocking? Sophos or pfSense blocking?
Sadly no, have no outbound rules set up.

To confirm this i've set up SMTP on nextcloud (located in a freenas jail) and it is working just fine, even though it is using the same physical interface,same VLAN/subnet, just different IP. I also shouldn't have been able to connect with "telnet smtp.gmail.com 587" if my firewall settings were the case.

The only weird networking issue i can think of is that i use LACP between my FreeNAS machine and my router, never had any issues with that however.

I'll try sniffing my connection tomorrow, maybe that will bring some light on what is wrong
 
Joined
Mar 2, 2019
Messages
4
Okay, i managed to solve it thanks to packet sniffering.
If anyone is interested, that was the problem:
UFVdK9i.png

For some reason when I've set-up my FreeNAS box i wrote my hostname with spaces. Changing it to FreeNasPleaseIgnore solved the issue.
Also, the reason my Mikrotik router was able to send SMTP just fine is because he was sending my ip as EHLO argument.

Thank you guys for giving me the idea to whip out wireshark!
 
Joined
Jan 4, 2014
Messages
1,644

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
Okay, i managed to solve it thanks to packet sniffering.
If anyone is interested, that was the problem:
UFVdK9i.png

For some reason when I've set-up my FreeNAS box i wrote my hostname with spaces. Changing it to FreeNasPleaseIgnore solved the issue.
Seems like that should be filed as a bug. Either that spaces shouldn't be allowed, or that they should be replaced when sending mail.
 
Top