How do I connect with Exchange server with Go? I have tried:
func main() {
to := "[email protected]"
from := "[email protected]"
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)
}
}
This code returns:
504 5.7.4 Unrecognized authentication type
I'm porting over Python/Django code, and it has a setting where I mark have to declare:
EMAIL_USE_TLS = True
Perhaps something similar in Go?