72

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.

Hiren Gohel
  • 4,942
  • 6
  • 29
  • 48
Milind Patel
  • 2,677
  • 4
  • 14
  • 31
  • The solution you linked is for another error "MapiExceptionNotFound", for your error take a look here: https://social.technet.microsoft.com/Forums/en-US/69426f64-717d-47e0-aa1b-700903ee83cc/520-storedrv-error?forum=exchangesvrsecuremessaginglegacy – dparoli Feb 20 '19 at 10:51
  • Your link also suggests the same. But i am unable to find clutter as mentioned – Milind Patel Feb 20 '19 at 11:05
  • You need to use the Sender header, not the From header. Make sure which header your client is affecting when you set the email address from which the mail is sent. – Paul-Sebastian Manole Oct 07 '20 at 10:58

9 Answers9

126

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.

Milind Patel
  • 2,677
  • 4
  • 14
  • 31
  • both email address same means ? – Mitul Marsoniya Nov 05 '19 at 13:44
  • 4
    The From email you are using to send in code and from the email you are actually sending. – Milind Patel Nov 05 '19 at 14:04
  • 3
    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. – Jake Dec 16 '19 at 08:34
  • 2
    Yes, I wasted my 7 days for this issue. Finally, this resolves my issue. Hope you have not wasted your this much time. – Milind Patel Dec 16 '19 at 08:43
  • how do you add one or more sender in outlook? – Irfan Dec 23 '19 at 03:53
  • 1
    Checkout this link. https://support.office.com/en-us/article/add-your-other-email-accounts-to-outlook-com-c5224df4-5885-4e79-91ba-523aa743f0ba – Milind Patel Dec 23 '19 at 05:00
  • This post should be upvoted and protected for future reference!. The exact solution for an exact problem. – Berker Yüceer Jan 29 '20 at 07:25
  • OMG, thanks a lot !!!!!!!! what I did in Laravel just change the config/mail from – Jackaroo Ng Feb 18 '20 at 13:53
  • The best answer ever, Milind Patel. – nosequeweaponer Jun 01 '20 at 17:22
  • 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 – JeanAlesi Aug 19 '20 at 20:11
  • 8
    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. – imclean Aug 29 '20 at 21:31
  • 1
    Take another 10 points, You are a genius haha ! – joedotnot Feb 17 '21 at 13:57
  • Thanks that was genious – surbhi agr Mar 03 '21 at 13:19
  • @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... – Auspex Apr 06 '21 at 14:15
  • @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? – imclean Apr 13 '21 at 04:32
  • 2
    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. – Betty Jun 11 '21 at 14:57
36

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.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
16

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: 'abcde@outlook.com',
                pass: '******'
            },
            tls: {
                rejectUnauthorized: false
            }
        });


        // setup email data with unicode symbols
        let mailOptions = {
            from: "abcde@outlook.com", // sender address
            to: 'xyz@gmail.com', // 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

Arun
  • 601
  • 10
  • 15
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: *** }

4

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
MAIL_USERNAME=myemail@hotmail.com (this must be the same as MAIL_FROM_ADDRESS!)
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=myemail@hotmail.com (this must be the same as MAIL_USERNAME!)

Everything worked after doing the above.

David Buck
  • 3,752
  • 35
  • 31
  • 35
dulerong
  • 231
  • 1
  • 3
  • 8
2

What works for me is to set DEFAULT_FROM_EMAIL as the EMAIL_HOST_USER. Working with Office 365 SMTP and Django 3.0.10.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
0

you can also use this Mail-Driver: https://github.com/motze92/office365-mail

Here you can specify any From-Email Address where your tenant has the permission for. Sent E-Mails will also go into the recipients sent items folder.

brokedid
  • 879
  • 2
  • 10
  • 35
0

for this issue check the jenkins system admin email it is be same as smtp user email

-1

In Spring boot Java you can fix this issue by following code.

application.properties file

spring.mail.properties.mail.smtp.connecttimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.host=smtp.office365.com
spring.mail.password=password
spring.mail.port=587
spring.mail.username=abc@outlook.com
spring.mail.properties.mail.smtp.starttls.enable=true
security.require-ssl=true
spring.mail.properties.mail.smpt.auth=true

Java class which impliments the mail functionality

@Component
public class MailSenderClass {

@Value("${spring.mail.username}")
private String from;

@Autowired
private JavaMailSender javaMailSender;

public void sendMail(String to, String subject, String body) throws MessagingException {
    MimeMessage message = javaMailSender.createMimeMessage();
    MimeMessageHelper helper;
    helper = new MimeMessageHelper(message, true);//true indicates multipart message
    helper.setFrom(from) // <--- THIS IS IMPORTANT
    helper.setSubject(subject);
    helper.setTo(to);
    helper.setText(body, true);//true indicates body is html
    javaMailSender.send(message);
}

}

Note: you have to helper.setFrom(from) is important , your issue will be resolved by adding that piece of code.

Khalid Habib
  • 1,100
  • 1
  • 16
  • 25