Office365 SMTP Mail Error on Auth: 535 5.7.139 Authentication unsuccessful. (Works fine locally)

257 Views Asked by At

We are using Office365 business basic. We are using one of our licensed account for SMTP email to send main to our users (outsiders). Our smtp client is written on GO lang. The service was working fine, but recently we found that the service can't send mail for some authentication issue. But in our local pc everything is working fine, even the same code/ program is working fine in our local pc. But when we try to send from our servers it throws error. We tried with many clients locally, everything is working fine. May be our servers added on blacklist or something else.


package mailer

import (
    "errors"
    "fmt"
    "net/smtp"
)

var ErrUnknown = errors.New("unknown from server")

type smtpAuth struct {
    username string
    password string
}

func (s smtpAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
    return "LOGIN", []byte(s.username), nil
}
func (s smtpAuth) Next(fromServer []byte, more bool) ([]byte, error) {
    if !more {
        return nil, nil
    }
    switch string(fromServer) {
    case "Username:":
        return []byte(s.username), nil
    case "Password:":
        return []byte(s.password), nil
    default:
        return nil, fmt.Errorf("%w: %q", ErrUnknown, string(fromServer))
    }
}

type Mailer struct {
    host     string
    port     string
    username string
    password string
}

func NewMailer(host, port, username, password string) *Mailer {
    return &Mailer{
        host:     host,
        port:     port,
        username: username,
        password: password,
    }
}

func (m *Mailer) Send(sender string, receiver []string, msg []byte) error {
    auth := smtpAuth{username: m.username, password: m.password}
    server := m.host + ":" + m.port
    return smtp.SendMail(server, auth, sender, receiver, msg)
}


This code is working fine in my local machine, but with same credential it's not working on my server

here is the log

Mail Error on Auth: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [SG2PR04CA0193.apcprd04.prod.outlook.com 2024-02-20T08:46:13.879Z 08DC309C8EDA8C92]
exit status 1

I am using the same code in my local machine, where it works fine. Even in my friends machine as well.

1

There are 1 best solutions below

3
Eugene Astafiev On

Microsoft no longer supports Basic Authentication, and they have disabled SMTP AUTH in all tenants. This is done to force customers to move from apps that use basic authentication to Modern authentication [OAuth 2.0].

See Deprecation of Basic authentication in Exchange Online for more information.