Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

SMTP mail Server error

Posted on by 4,184

On Post of sales order an email has to be sent to the customer with attachment of the order, while i do that i get the following error

The SMTP Mail system returned the following error : A recipient must be specified

The following is the code I used 

SendEmailWithAttachment(CustNo : Code[20])

Customer.RESET;
Customer.SETRANGE("No.",SalesHeader."Sell-to Customer No.");
IF Customer.FINDFIRST THEN
CustEmail:=Customer."E-Mail";

SMTPMailSetup.GET;
FileName:=FileManagement.ServerTempFileName('pdf');
//FileName:=SMTPMailSetup."Path to Save Reports"+'Statement'+'.pdf';
REPORT.SAVEASPDF(205,FileName,SalesHeader);
SMTPMail.CreateMessage(SMTPMailSetup."Sender Name",SMTPMailSetup."User ID",CustEmail,'Sales Order','',TRUE);

SMTPMail.AddAttachment(FileName,SalesHeader."Sell-to Customer No."+'.pdf');
SMTPMail.AppendBody('Dear Sir');
SMTPMail.AppendBody('<br><br>');
SMTPMail.AppendBody('Please find the attachment');
SMTPMail.AppendBody('<br><br>');

SMTPMail.Send;
MESSAGE('Mail send to Customer');

*This post is locked for comments

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 on at
    RE: SMTP mail Server error

    Hey CDsilva,

    Error Message seems very clear as its expecting a recipient address. Please add recipient and then try.

    Please let us know if its executed. 

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: SMTP mail Server error

    In your program your forget to write the code for whom you want to send email

    If you want send email to customer then then use AddRecipient function

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SMTP mail Server error

    Hey ,

    Your SMTP setup is properly updated ???also please check whether the email id is updated in customer card or not. It seems code is not able get the customer email I'd which is required to send the email.

    Also you can make an entermediate table to make a log for the email send communication. Thur which you can check which mail is not sent and what was the reason while sending mail thru send mail function.  "Just Error Handling "

    Thanks

  • Suggested answer
    Binesh Profile Picture
    Binesh 7,885 on at
    RE: SMTP mail Server error

    Hello,

    Re-write your code, bellow the corrected code.

    earlier seems to blank Customer Email,.

    ------------------------------------

    SendEmailWithAttachment(CustNo : Code[20])
    Customer.RESET;
    Customer.SETRANGE("No.",SalesHeader."Sell-to Customer No.");
    IF Customer.FINDFIRST THEN
    IF Customer."E-Mail" <> '' THEN
    CustEmail:=Customer."E-Mail"
    ELSE
    ERROR('Customer E-Mail is blank');
    SMTPMailSetup.GET;
    FileName:=FileManagement.ServerTempFileName('pdf');
    //FileName:=SMTPMailSetup."Path to Save Reports"+'Statement'+'.pdf';
    REPORT.SAVEASPDF(205,FileName,SalesHeader);
    SMTPMail.CreateMessage(SMTPMailSetup."Sender Name",SMTPMailSetup."User ID",CustEmail,'Sales Order','',TRUE);
    SMTPMail.AddAttachment(FileName,SalesHeader."Sell-to Customer No."+'.pdf');
    SMTPMail.AppendBody('Dear Sir');
    SMTPMail.AppendBody('<br><br>');
    SMTPMail.AppendBody('Please find the attachment');
    SMTPMail.AppendBody('<br><br>');
    SMTPMail.Send;
    MESSAGE('Mail send to Customer');

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: SMTP mail Server error

    Make sure CustEmail has a value, do check before creating above code and could also add the below statement to be clear.

    Add this line of code before the SMTPMail.Send

    SMTPMail.AddRecipients(CustEmail);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SMTP mail Server error

    Hi CDsilva,

    Check if email address is specified in your customer card.

    You can include the below validation in your code :

    IF  CustEmail <> '' THEN

    //Create and Send Mail

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,137 Super User 2024 Season 2 on at
    RE: SMTP mail Server error

    where did you write above code.

    please check whether salesheader is not deleted by the time above code is executed.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans