Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

SMTP Setup on smtp.office365.com in NAV 2016

Posted on by 1,112

Hi,

My client has configured the SMTP Mail Setup on smtp.office365.com. And the Test mail functionality is giving the below error message...

smtpError.PNG

But we could sent sms thru custom code. My JOB Queue notification is not working due to the issue.

I have debugged to understand the issue, I found that the Codeunit 412 SMTP Test Mail has a function called "SendTestMail", its code as under.

SMTPMailSetup.GET;   //Table 409

SMTPMail.CreateMessage(                                //Codeunit 400
  '',
  EmailAddress,   //first
  EmailAddress,
  TestMailTitleTxt,
  STRSUBSTNO(
    TestMailBodyTxt,
    USERID,
    SMTPMailSetup."SMTP Server",
    FORMAT(SMTPMailSetup."SMTP Server Port"),
    SMTPMailSetup.Authentication,
    SMTPMailSetup."Secure Connection",
    SERVICEINSTANCEID,
    TENANTID),
  TRUE);

SMTPMail.Send;
MESSAGE(TestMailSuccessMsg,EmailAddress);

The above code is working fine when the smtp setup is rather than smtp.office365.com. But it is very strange to see if I replace the first "EmailAddress" by SMTPMailSetup."User ID" then it's working fine. but still JOB Queue notification is not working.

Kindly reply to solve this matter.

Thank youu,

Subrata Bauri 

  • Suggested answer
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    Please re-read my answers and note that I'm taking about FROM e-mail address - not the TO e-mail address

    This error has nothing to do with who you are sending TO, it is only related to who you are sending FROM.

    In your working example you are sending FROM SMTPSetup."User ID". And it is not really a surprise that an Office365 user can send from his own e-mail address.

    In the non-working example you are sending FROM another e-mail address. Probably either the one setup on the NAV/BC login account or the company e-mail. It depends on your version of NAV/BC.

    That exact address needs to be whitelisted in Office365 for this to work.

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    when trying to send an email to subrata@xyz.com from Test Mail (thru SMTP Mail Setup) the error comes as SendAsDeniedException but I can send email to subrata@xyz.com thru below code....

    SMTPSetup.GET;
    
    SMTPMail.CreateMessage("From Name",SMTPSetup."User ID","Send to",Subject......

  • Suggested answer
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    Still - if the error is SendAsDeniedException it is because you are sending from a e-mail address that is not whitelisted in Office365. Can't remember if you are allowed to select that on a test e-mail or it just picks the one from company info..

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    Hi Gert,

    We can sent email thru Coding but smtp test mail is not working.  

    On the other hand, smtp test mail working fine if smtp server is rather than office365.

  • Suggested answer
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    Your error is "SendAsDeniedException". This is an Office365 related issue and not a NAV/Business central related issue.

    In Office365 you are only allowed to state the sending address as the one setup on the login account. It is a security mechanism and is not a limitation of NAV/Business Central.

    This is to make sure nobody misuses the Office365 account to send e-mail from another e-mail (i.e. Joe Jobbing or similar - see https://en.wikipedia.org/wiki/Joe_job).

    You can - however - add/whitelist other sending addresses in the same email domain by granting the login account "send as" or "send on behalf of" (can't remember which one right now). But that requires you to know and having a limited set of sending addresses before hand. Please see https://docs.microsoft.com/en-us/office365/admin/add-users/give-mailbox-permissions-to-another-user?view=o365-worldwide about how to grant those permissions in Office365.

    Note - as an alternative you can use another SMTP service to send e-mails. If you have Azure services anyway, you can add a SendGrid account with 25,000 free e-mails/month: see https://docs.microsoft.com/en-us/azure/sendgrid-dotnet-how-to-send-email (ignore the part about how to send e-mails from DotNet).

  • subrata.bauri Profile Picture
    subrata.bauri 1,112 on at
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    Thanks for your reply...

    I have some doubt about the undocument feature of this matter. BTW, Kindly inform me the version where MS had rectified the same.

    My Version is NAV 2016 CU 48 (Object version -Object Codeunit 9520 Version NAVW19.00.00.45778)

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: SMTP Setup on smtp.office365.com in NAV 2016

    The one you replaced is the sender email address, In your version do you codeunit 9520? if so replace above with the following where MailManagement is 9520

    SMTPMail.CreateMessage(

     '',

     MailManagement.GetSenderEmailAddress,

     EmailAddress,

     TestMailTitleTxt,

     STRSUBSTNO(

       TestMailBodyTxt,

       USERID,

       SMTPMailSetup."SMTP Server",

       FORMAT(SMTPMailSetup."SMTP Server Port"),

       SMTPMailSetup.Authentication,

       SMTPMailSetup."Secure Connection",

       SERVICEINSTANCEID,

       TENANTID),

     TRUE);

    SMTPMail.Send;

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans