Open Dontmindmes opened 5 years ago
Seconded. I have seeing the same issue too. follow https://support.google.com/mail/?p=BadCredentials, turn on access for less secure apps, but it didn't work.
see #108
Hi, I have this problem too!! does anyone solve this issue? I didn't find anything in #108 as @pedromorgan mentioned in the above comment.
@Alireza-cman did you finally find a solution? I am also experiencing this issue.
I had a similar problem connecting to office365. Office 365 needs LoginAuth. I achieved this by creating a custom method to implement this. Create a file and paste the below code
import (
"net/smtp"
"errors"
)
type loginAuth struct {
username, password string
}
func LoginAuth(username, password string) smtp.Auth {
return &loginAuth{username, password}
}
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
return "LOGIN", []byte{}, nil
}
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
if more {
switch string(fromServer) {
case "Username:":
return []byte(a.username), nil
case "Password:":
return []byte(a.password), nil
default:
return nil, errors.New("Unkown fromServer")
}
}
return nil, nil
}
Generate LoginAuth below
...
auth := LoginAuth(username, password)
...
Then add the generated auth to gomail
...
d := gomail.NewDialer(server, port, username, pass)
d.Auth = auth // add LoginAuth generated above
// Send the email
if err := d.DialAndSend(m); err != nil {
log.Printf(" cant send email got error %s ", err.Error())
return false
}
...
@mudphilo thanks, it worked
`panic: 535 5.7.8 Username and Password not accepted. Learn more at 5.7.8 https://support.google.com/mail/?p=BadCredentials 195sm9531505pfc.50 - gsmtp
goroutine 1 [running]: main.SendEmail()`