I want to send an email using Outlook servers, but I'm getting an error 504 5.7.4 Unrecognized authentication type
Here's the snippet.
func sendEmail() {
server := "smtp-mail.outlook.com
port := 587
user := "foo@outlook.com"
from := user
pass := "foobar"
dest := "bar@gmail.com"
auth := smtp.PlainAuth("", user, pass, server)
to := []string{dest}
msg := []byte("From: " + from + "
" +
"To: " + dest + "
" +
"Subject: Test outlook
" +
"OK")
endpoint := server + ":" + port
err := smtp.SendMail(endpoint, auth, from, to, msg)
if err != nil {
log.Fatal(err)
}
}
If instead of sending the email using outlook, I use gmail, it works fine.
In Python, I can send the email using outlook with the following code:
server = smtplib.SMTP(server, port)
server.starttls()
server.login(user, password)
server.sendmail(from, to, msg)
server.quit()
So I guess I'm missing something in my Go code. According to the doc, SendMail
switches to TLS
, so that shouldn't be the issue.
auth := smtp.PlainAuth("", user, pass, server)
This is using the authentication method PLAIN. Unfortunately smtp-mail.outlook.com does not support this authentication method:
> EHLO example.com
< 250-AM0PR10CA0007.outlook.office365.com Hello ...
< 250- ...
< 250-AUTH LOGIN XOAUTH2
Thus, only LOGIN and XOAUTH2 are supported as authentication methods.
server.login(user, password)
Python supports LOGIN so it will succeed.
Golang smtp does not support LOGIN. But this gist seems to provide a working fix by adding this missing authentication method.
要使用 Outlook 的 SMTP 服务器发送电子邮件,请按照以下步骤进行操作:
打开 Outlook,然后选择“文件”选项卡。
在“信息”下选择“账户设置”,然后选择“服务器设置”。
在“服务器设置”窗口中,选择“电子邮件”选项卡,然后选择您要使用的电子邮件帐户。
单击“更改”按钮以修改您的电子邮件设置,确保以下设置正确:
用户名和密码:输入您的电子邮件地址和密码。
服务器信息:选择要使用的电子邮件服务器和端口,SMTP 服务器为“smtp.office365.com”,端口号为“587”。
加密方法:选择“TLS”进行加密。
身份验证要求:选择“需要身份验证”。
在完成设置后,单击“测试帐户设置”,以确保您的设置是正确的,然后单击“关闭”,关闭窗口。
现在您可以使用 Outlook 的 SMTP 服务器发送电子邮件了。要发送邮件,请在“新邮件”窗口中添加收件人、主题和内容,然后单击“发送”。
希望这些步骤可以帮助您使用 Outlook 的 SMTP 服务器发送电子邮件。如果您遇到任何问题,请联系您的电子邮件服务提供商或技术支持。
另外,如果您使用的是 Outlook.com,您也可以使用以下 SMTP 服务器发送电子邮件:
SMTP 服务器地址:smtp.office365.com
端口:587
加密方法:TLS
身份验证:是,需要用户名和密码
如果您使用的是 Gmail,以下是使用 Outlook 的 SMTP 服务器发送电子邮件所需的设置:
SMTP 服务器地址:smtp.gmail.com
端口:587
加密方法:TLS 或 SSL
身份验证:是,需要用户名和密码
请注意,某些电子邮件服务提供商可能需要使用不同的端口或加密参数。如果您无法使用上述步骤成功发送电子邮件,请参考您的电子邮件服务提供商的文档或联系他们的技术支持,获取更多帮助和信息。