Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Username and Password not accepted #133

Open
Dontmindmes opened this issue Mar 11, 2019 · 6 comments
Open

Username and Password not accepted #133

Dontmindmes opened this issue Mar 11, 2019 · 6 comments

Comments

@Dontmindmes
Copy link

Dontmindmes commented Mar 11, 2019

m := gomail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetHeader("To", "[email protected]")
m.SetHeader("Subject", "Hello!")
m.Embed("passlist.rxt")
m.SetBody("text/html", ``)

d := gomail.NewPlainDialer("smtp.gmail.com", 587, "[email protected]", "ss")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

if err := d.DialAndSend(m); err != nil {
	panic(err)
}

`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()`

@shcabin
Copy link

shcabin commented Jun 3, 2019

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.

@pedromorgan
Copy link

see #108

@Alireza-cman
Copy link

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.

@the-fanan
Copy link

@Alireza-cman did you finally find a solution? I am also experiencing this issue.

@mudphilo
Copy link

mudphilo commented Nov 26, 2020

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
}
...

@goeroeku
Copy link

goeroeku commented Sep 9, 2021

@mudphilo thanks, it worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants