Sending Email (Html Code) - using SMTP

sunnyk
Member Posts: 280
Hello, We created a New report and wrote the attached Code to send Email certain data to one user.

Attached is the SMTP setting on our NAV server.

However, we executed the report, we got the error
Microsoft Dynamics NAV
The SMTP mail system returned the following error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [KL1PR0601CA0015.apcprd06.prod.outlook.com]".

Attached is the SMTP setting on our NAV server.

However, we executed the report, we got the error
Microsoft Dynamics NAV
The SMTP mail system returned the following error: "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [KL1PR0601CA0015.apcprd06.prod.outlook.com]".
0
Best Answer
-
Check functionality to use same "sides" (client/server).5
Answers
-
The user in smtp setup can't send on behalf of the sender you have in SMTPMail.CreateMessage()
Try set the sender in SMTP.Message() to NAV_Notification[what's behind red box] to test if can can send at all. if success then set up permissions to send as or send on behalf in office3650 -
Try "SMTP Mail Setup" / "Test Email Setup" ?0
-
Hi,
Yes, here is the code that we wrote, and we rae taking sender from SMTP setup,Purch. Rcpt. Line - OnPreDataItem() CLEAR(SMTPMail); SMTPSetup.GET; //SETRANGE("Posting Date",WORKDATE); Recipients:= 'myName@CorpXY.com'; Subject := 'Expense Receipt Notification' + ': ' + FORMAT(WORKDATE); Body := 'Following Items are received on :' + FORMAT(WORKDATE); CLEAR(SMTPMail); SMTPMail.CreateMessage('XYZ',SMTPSetup."User ID",Recipients,Subject,'',TRUE); SMTPMail.AppendBody('Hello,'); SMTPMail.AppendBody('<br><br>'); SMTPMail.AppendBody('<h1>'+ Body + '</h1>'); SMTPMail.AppendBody('<br><br>'); SMTPMail.AppendBody('<table border="1">'); SMTPMail.AppendBody('<tr>'); SMTPMail.AppendBody('<th><b>Document No.</th>'); SMTPMail.AppendBody('<th><b>Order No.</th>'); SMTPMail.AppendBody('<th><b>Item No.</th>'); SMTPMail.AppendBody('<th><b>Description</th>'); SMTPMail.AppendBody('<th><b>Quantity</th>'); SMTPMail.AppendBody('<th><b>Unit Cost(LCY)</th>'); SMTPMail.AppendBody('<th><b>Amount(LCY)</th>'); SMTPMail.AppendBody('</tr>'); Purch. Rcpt. Line - OnAfterGetRecord() SMTPMail.AppendBody('<tr>'); SMTPMail.AppendBody('<td>' + FORMAT("Document No.") + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT("Order No.") + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT("No.") + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT(Description) + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT(Quantity) + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT("Unit Cost (LCY)") + '</td>'); SMTPMail.AppendBody('<td>' + FORMAT("Unit Cost (LCY)" * Quantity) + '</td>'); SMTPMail.AppendBody('</tr>'); Purch. Rcpt. Line - OnPostDataItem() SMTPMail.AppendBody('</table>'); SMTPMail.AppendBody('<br><br>'); SMTPMail.AppendBody('Thanks '); SMTPMail.AppendBody(' '); SMTPMail.AppendBody('<br><br>'); SMTPMail.AppendBody('<hr>'); SMTPMail.AppendBody('This is system generated mail. Please do not reply to this mail id.'); SMTPMail.Send;
if i replace NAV_Notifications@abc.com to myname@abc.com in SMTP setup and update my password, this works. but how this NAV_notifications is able to send PO and SO approval emails within NAV and not like this?0 -
When your Email address works, then is either the password wrong or there is a problem with the settings of the Mail-account in O365.My blog - https://www.HannesHolst.com/1
-
Hi,
The password is correct, because when I test nav_notification from SMTP setup using test email setup and send email to itself i.e. nav_notification it's working but when I choose other and give some other email address, it fails. But how this particular id Nav_notification is able to send Purchase orders/Sales Orders approval and rejection notifications to users. Also, when I Use my Id on SMTP setup and try to send mail using Test Email setup to any other address, that also fails, but using the code it works.0 -
Check functionality to use same "sides" (client/server).5
-
Sorry, but I didn't get what you meant by Same "Side".0
-
if you meant, that i use same Nav_notifications for both sender & recipient, yes it works even through code.0
-
Hello,
This is resolved. Instead of using SMTP user ID(which is actually an office 365 EMail ID), i use a User id from User setup whose email is SMTP UserID.0 -
Has anyone found a way to use a html editor in a NAV page?
I found the following posts, has anyone experience with these?
https://www.hougaard.com/wysiwyg-editing-control-for-dynamics-nav-2013-and-2015/
https://mibuso.com/downloads/pawnhtmltexteditor-v1.2
0 -
Don't do universal application from NAV. 3rd party applications are often easy to implement for particular tasks.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions