Mail Error: SMTP Connection timed out
Xeway opened this issue · 2 comments
Xeway commented
Hey,
I'm trying to send emails from an outlook address but I get the error Mail Error: SMTP Connection timed out
after the time out.
Here's the informations provided by Microsoft (found two sources, one from Microsoft's support, the other from email's settings):
SMTP hostname: smtp-mail.outlook.com (or smtp.office365.com, tried both)
Port: 587
Encryption: STARTTLS
Here's my code:
server := mail.NewSMTPClient()
server.Host = os.Getenv("SMTP_HOST")
server.Port = 587
server.Username = os.Getenv("EMAIL")
server.Password = os.Getenv("EMAIL_PASSWORD")
server.Encryption = mail.EncryptionSTARTTLS
server.KeepAlive = false
smtpClient, err := server.Connect()
if err != nil {
return err
}
body := "<html><body><p>Hey,</p><p><a href='" +
os.Getenv("SERVER_ADDRESS") +
"/verifyEmail?code=" +
code +
"'>Click here to confirm your email</a></p><p>Cordially,</p></body></html>"
email := mail.NewMSG()
email.SetFrom("Test Email <" + os.Getenv("EMAIL") + ">").
AddTo("<a real address>").
SetSubject("E-mail verification")
email.SetBody(mail.TextHTML, body)
if email.Error != nil {
return email.Error
}
err = email.Send(smtpClient)
if err != nil {
return err
}
Thanks in advance for your help!
xhit commented
Hi.
Did you try to increase the server.ConnectTimeout?
The default server.ConnectTimeout is 10 seconds, maybe from your network you need to increase this.
I tried with smtp.office365.com
Also, use login auth with outlook with server.Authentication
Xeway commented
Hey,
I added this line server.Authentication = mail.AuthLogin
and it works!
Thanks so much for your help