jordan-wright / email

Robust and flexible email library for Go
MIT License
2.61k stars 324 forks source link

504 5.7.4 Unrecognized authentication type #113

Open maxiride opened 4 years ago

maxiride commented 4 years ago

I've tried to run the example in the README using the outlook smtp servers:

However the package doesn't send the email and throws the error:

panic: 504 5.7.4 Unrecognized authentication type [ZR0P278CA0037.CHEP278.PROD.OUTLOOK.COM]

Snippet of MWE:

func send(text, html []byte) {

    m := &email.Email{
        From:    "myself",
        To:      []string{"my@email.com"}, // redacted
        Subject: "Test emails",
        Text:    text,
        HTML:    html,
        Sender:  "my@email.com", // redacted
    }

    mailServer := os.Getenv("SMTP_SERVER") + ":" + os.Getenv("SMTP_PORT")
        // outputs smtp-mail.outlook.com:587

    auth := smtp.PlainAuth("", os.Getenv("SMTP_USERNAME"), os.Getenv("SMTP_PASSWORD"), os.Getenv("SMTP_SERVER"))
       // SMT_SERVER is smtp-mail.outlook.com

    err := m.Send(mailServer, auth)
    if err != nil {
        panic(err)
    }
}

Upon further research https://github.com/go-gomail/gomail/issues/16 might be related but I'm still digging.

bfarayev commented 3 years ago

I have a very similar setting to yours, except for the smtp port I'm using 25 and point it to an Exchange server. getting exactly the same issue when I'm trying to do smtp.PlainAuth

The server I'm using supports only AUTH LOGIN extension (you can check ehlo) and it might be reason in my case. What AUTH types does your server support? Based on this, seems like no auth is supported but I might be missing something:

telnet smtp-mail.outlook.com 25
Trying 52.98.0.194...
Connected to syd-efz.ms-acdc.office.com.
Escape character is '^]'.
220 SYBPR01CA0043.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 20 Aug 2020 00:16:49 +0000
ehlo smtp-mail.outlook.com
250-SYBPR01CA0043.outlook.office365.com Hello [203.87.114.82]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
AUTH LOGIN
504 5.7.4 Unrecognized authentication type [SYBPR01CA0043.ausprd01.prod.outlook.com]
AUTH PLAIN
504 5.7.4 Unrecognized authentication type [SYBPR01CA0043.ausprd01.prod.outlook.com]
bfarayev commented 3 years ago

Just realized that this package doesn't support AUTH LOGIN just yet. It's not hard to implement and there's an open PR for it here but it's not merged yet: https://github.com/jordan-wright/email/issues/104

I'd like to get @jordan-wright to have a look. Whoever uses Outlook / Exchange Server will have this issue

cuiko commented 2 years ago

it's working for me. https://github.com/go-gomail/gomail/issues/16#issuecomment-73672398

e := email.NewEmail()
addr := "smtp.office365.com:587"
auth := LoginAuth(username, password)
tlsConfig := &tls.Config{
  ServerName: "smtp.office365.com",
}
e.SendWithStartTLS(addr, auth, tlsConfig)