【发布时间】:2017-07-07 10:36:39
【问题描述】:
如何使用 Go 连接 Exchange 服务器?我试过了:
func main() {
to := "first.last@acme.com"
from := "me@acme.com"
password := "myKey"
subject := "Subject Here"
msg := "Message here"
emailTemplate := `To: %s
Subject: %s
%s
`
body := fmt.Sprintf(emailTemplate, to, subject, msg)
auth := smtp.PlainAuth("", from, password, "smtp.office365.com")
err := smtp.SendMail(
"smtp.office365.com:587",
auth,
from,
[]string{to},
[]byte(body),
)
if err != nil {
log.Fatal(err)
}
}
此代码返回:
504 5.7.4 Unrecognized authentication type
我正在移植 Python/Django 代码,它有一个设置,我标记必须声明:
EMAIL_USE_TLS = True
也许在 Go 中有类似的东西?
【问题讨论】:
标签: go smtp exchange-server