37

This Go program successfully sends email from my home computer, but on a virtual server on DigitalOcean receives the following error:

panic: 530 5.5.1 Authentication Required. Learn more at

Here's the code:

auth := smtp.PlainAuth("", "bjorkbjorksen@gmail.com", "PASSWORD", "smtp.gmail.com")
msg := "Subject: Hello\r\n\r\nWorld!"
e = smtp.SendMail("smtp.gmail.com:587", auth, "bjorkbjorksen@gmail.com", []string{email}, []byte(msg))
if e != nil { panic(e) }
Calder
  • 2,219
  • 1
  • 20
  • 21

5 Answers5

39

Get to your Gmail account's security settings and set permissions for "Less secure apps" to Enabled. Worked for me.

MichaelZi
  • 407
  • 4
  • 2
13

Derp! I signed into the account and there was a "Suspicious login attempt" warning message at the top of the page. After clicking the warning and authorizing the access, everything works.

Calder
  • 2,219
  • 1
  • 20
  • 21
8

You need to go here https://security.google.com/settings/security/apppasswords

then select Gmail and then select device. then click on Generate. Simply Copy & Paste password which is generated by Google.

ujjaval
  • 1,523
  • 4
  • 20
  • 35
0

You need turn on the POP mail and IMAP mail feature in setting of the email you are using to send mail. Good luck!

Davis
  • 117
  • 3
0

in may case setting SMTPAuth to true fixed it. Of-course you need to set permissions for "Less secure apps" to Enabled.

$mail->SMTPAuth = true;

sk md
  • 83
  • 1
  • 10