Unable to send SMTP mails using office365 settings

120,287

Solution 1

Outlook doesn't provide to send using different from address other than your username to log in.

You need both email address same.

You can add one or more sender in your admin panel after that you can send easily from different addresses.

Solution 2

This error means the user whose credentials you specified in the SMTP connection cannot submit messages on behalf of the user specified in the From and/or Sender MIME headers or the FROM SMTP command.

Solution 3

I face the similar issue and i resolved it right now, you are most likely facing this issue because your "user" email in the auth option and the "from" email at the mail option are different

make the user and from email same and it will work for you

const transporter = nodemailer.createTransport({
            service: 'outlook',
            port: 587,
            auth: {
                user: '[email protected]',
                pass: '******'
            },
            tls: {
                rejectUnauthorized: false
            }
        });


        // setup email data with unicode symbols
        let mailOptions = {
            from: "[email protected]", // sender address
            to: '[email protected]', // list of receivers
            subject: 'Node Contact Request', // Subject line
            text: 'Hello world?', // plain text body
            html: output // html body
        };

        // send mail with defined transport object
        transporter.sendMail(mailOptions, (error, info) => {
            console.log(info);
            if (error) {
                return console.log(error);
            }
            console.log('Message sent: %s', info.messageId);
            console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
        });

If your email is not verified you will likely to get more errors

Solution 4

After trying for 4 days, mails started to triggered with port:25, so instead of trying with 587 or 465. Try with other port numbers.

host: "smtp.office***.*", port:25, secureConnection: false, requireTLS: true, tls: { ciphers: 'SSLv3' }, auth: { user: *, pass: *** }

Solution 5

I used Hotmail and had this problem but solved it by editing MAIL_FROM_ADDRESS to be the same as MAIL_USERNAME

Below is my env file set up.

MAIL_MAILER=smtp
MAIL_HOST=smtp-mail.outlook.com
MAIL_PORT=587
[email protected] (this must be the same as MAIL_FROM_ADDRESS!)
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
[email protected] (this must be the same as MAIL_USERNAME!)

Everything worked after doing the above.

Share:
120,287
Milind Patel
Author by

Milind Patel

I am good at problem solving and decision taking and applying it to developing and coding.

Updated on July 05, 2022

Comments

  • Milind Patel
    Milind Patel almost 2 years

    I am using SMTP mail for sending mail using Laravel. Everything working perfect other than office365 mail settings.

    Settings I have used is as below:

    SMTP HOST = smtp.office365.com
    SMTP PORT = 587
    SMTP ENCRYPTION = tls
    SMTP USER = username(email)
    SMTP PASS = password
    

    Error i am getting is:

    554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message

    I have already searched google a lot for this error everybody says about clutter like this link Solution to this error But I personally don't find any clutter after followed all the steps mentioned.

    I cannot log in this email as it's our client email id and I don't have permission to log in.

    I also created one outlook email id and test this email setting. It worked like charm. I don't know what is wrong with Client email id.

    Any suggestions would be great.

  • IfElseTryCatch
    IfElseTryCatch about 5 years
    I have been stuck with this error for 4 full days. I will think about you every day of my life, Sir!!
  • Mitul Marsoniya
    Mitul Marsoniya over 4 years
    both email address same means ?
  • Milind Patel
    Milind Patel over 4 years
    The From email you are using to send in code and from the email you are actually sending.
  • Jake
    Jake over 4 years
    This solved the problem for me. I was using the Wordpress plugin Easy WP SMTP and I needed to make sure the "From Email Address" and "SMTP Username" were the same.
  • Milind Patel
    Milind Patel over 4 years
    Yes, I wasted my 7 days for this issue. Finally, this resolves my issue. Hope you have not wasted your this much time.
  • Irfan
    Irfan over 4 years
    how do you add one or more sender in outlook?
  • Milind Patel
    Milind Patel over 4 years
  • Berker Yüceer
    Berker Yüceer about 4 years
    This post should be upvoted and protected for future reference!. The exact solution for an exact problem.
  • Jackaroo Ng
    Jackaroo Ng about 4 years
    OMG, thanks a lot !!!!!!!! what I did in Laravel just change the config/mail from
  • nosequeweaponer
    nosequeweaponer almost 4 years
    The best answer ever, Milind Patel.
  • JeanAlesi
    JeanAlesi over 3 years
    I love this post! Deciphering it was a bit of a challenge at first sight. But once I figured out what he meant, I felt satisfaction
  • imclean
    imclean over 3 years
    This is crazy. I guess it's just too easy return an error message like "From header address does not match envelope sender." or "Username and email address don't match." SMTP is an open standard. Microsoft should not be returning implementation specific messages via SMTP, these belong in the server logs. Ideally we'd have no idea what environment we're sending through. There is no way we should be spending hours searching for the meaning of an SMTP error before we can even start to find a solution.
  • joedotnot
    joedotnot about 3 years
    Take another 10 points, You are a genius haha !
  • surbhi agr
    surbhi agr about 3 years
    Thanks that was genious
  • Auspex
    Auspex about 3 years
    @imclean It's worse than that! Not only should MS not be returning an implementation dependent message, but Postfix is telling me warning: smtp.office365.com[40.100.175.146]:587: response longer than 2048: , which implies it's not even strictly legal...
  • imclean
    imclean about 3 years
    @Auspex What's the full response, including error code? I'm not sure what applies here but reply lines can be 512 octets (4096 bits). This can probably be configured within Postfix. Is this error appearing in response to error reported above?
  • Betty
    Betty almost 3 years
    Your answer works, but unfortunately the page you link says "Microsoft will be removing the ability to connect new accounts to Outlook.com from May 10, 2021." It seems that they already removed it and we can't add other sending addresses now.