Gomail with gmail does not work

I am trying to use this module:

I put in the sample code found here:

  • PREFIX pkg.go.dev/gopkg.in/gomail.v2#example-package

PREFIX=https://

I changed:

d := gomail.NewDialer(“smtp.example.com”, 587, “user”, “123456”)

so that “example” became “gmail” and the user and password are correct. I also tried changing 587 to 465.

Neither work. I get the error:
panic: 535 5.7.8 Username and Password not accepted. For more information, go to
5.7.8 PREFIX support . google . com / mail / ?p=BadCredentials 6a1803df08f44-6c340bfa70asm21454206d6.12 - gsmtp

What do I need to do to fix it?

If you are 100% sure that all the data is correct, and even so you get the same error message, I would recommend testing with another email library, the last commit of go-gomail/gomail was 8 years ago;

I recommend go-mail

For me, with the code below, the email was delivered (after replacing all “XXX”):

package main

import (
    "gopkg.in/gomail.v2"
)

func main() {
    d := gomail.NewDialer("smtp.gmail.com", 587, "XXX@gmail.com", "XXX")
    msg := gomail.NewMessage()
    msg.SetHeader("From", "XXX@gmail.com")
    msg.SetHeader("To", "XXX")
    msg.SetHeader("Subject", "does gopkg.in/gomail.v2 work with gmail?")
    msg.SetBody("text/plain", "yes, it does!")
    _ = d.DialAndSend(msg)
}

Are you certain about your credentials?

Is 2-Step-Verification turned on in your account?
Did you set up App passwords?

Or are you using the password from your google account?
That will not work for smtp.

1 Like