go-gomail / gomail

The best way to send emails in Go.
MIT License
4.37k stars 577 forks source link

It will become less secure app when send to gmail #28

Closed bronze1man closed 9 years ago

bronze1man commented 9 years ago

I use gmail account to send a email,but it return a error with a warning. I can fixed it by turn off some secure stuff. https://support.google.com/accounts/answer/6010255?hl=en

Can this stuff be fixed in this library?

alexcesaro commented 9 years ago

Which port do you use? Can you show your code?

bronze1man commented 9 years ago

Here is my code.

func sendToGmail()(err error){
    addr:="xxx@gmail.com"
    msg := gomail.NewMessage()
    msg.SetHeader("From", addr)
    msg.SetHeader("To", addr)
    msg.SetHeader("Subject", "测试邮件1")
    msg.SetBody("text/html", "测试邮件2")

    mailer:=gomail.NewMailer("smtp.gmail.com","xxx@gmail.com","xxxx",587,
    gomail.SetTLSConfig(&tls.Config{InsecureSkipVerify: true}))
    return mailer.Send(msg)
}

Here is the error

panic: 534 5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtAP
5.7.14 mQRlt2S9ePao63HrBtSFL1b1MG3Ocz18RUf-xxxx
5.7.14 UT-xxx
5.7.14 HQhxZ_UwksmmOn40ozznhsLBJTAMx5KoSOEQ4dn7zGLYHiwfWkXv3ZbGmKawb4yeGcrlSj
5.7.14 e7Syp0nSjFiK6jN05nIseC97iU_Q> Please log in via your web browser and
5.7.14 then try again.
5.7.14 Learn more at
5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 r8sm2320369pdp.10 - gsmtp
alexcesaro commented 9 years ago

Do you also get this error when you remove the custom TLS configuration?

bronze1man commented 9 years ago

Yes.

alexcesaro commented 9 years ago

I think there are two ways to fix this issue:

In both cases it is outside the scope of Gomail. Although if you or someone else implements an Oauth2 authentication mechanism I might consider adding it to Gomail.

bronze1man commented 9 years ago

Thanks for your great job. I will turn off the secure option.

swill commented 7 years ago

I am also having this issue. Is this still the most up to date way to make gomail work with Gmail? I am confused how enabling 2step would help this. Wouldn't that mean that gomail would never be able to login because it will never be able to authenticate with the second auth mechanism?

swill commented 7 years ago

I was able to get this working by using the 2step verification and by generating an 'app token' which is used as the password in this case. Thanks...