5.5.1需要身份验证.更多信息请访问



这个Go程序成功地从我的家用电脑发送电子邮件,但是在DigitalOcean的虚拟服务器上收到以下错误:

panic: 530 5.5.1 Authentication Required. Learn more at

代码如下:

auth := smtp.PlainAuth("", "bjorkbjorksen@gmail.com", "PASSWORD", "smtp.gmail.com")
msg := "Subject: HellornrnWorld!"
e = smtp.SendMail("smtp.gmail.com:587", auth, "bjorkbjorksen@gmail.com", []string{email}, []byte(msg))
if e != nil { panic(e) }

进入您的Gmail帐户的安全设置,并将"不太安全的应用"的权限设置为Enabled

我登录了这个账户,页面顶部出现了一条"可疑登录尝试"的警告信息。单击警告并授权访问后,一切正常。

你需要到这里https://security.google.com/settings/security/apppasswords

选择Gmail,然后选择设备。然后单击Generate。只需复制&粘贴由Google生成的密码

您需要在用于发送邮件的电子邮件的设置中打开POP邮件和IMAP邮件功能。好运!

在某些情况下,将SMTPAuth设置为true可以解决此问题。当然,你需要将"不太安全的应用程序"的权限设置为启用。

$mail-> smtpath = true

最新更新