web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

SMTP mail Server error

(0) ShareShare
ReportReport
Posted on by 4,188

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

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    60,993 Super User 2025 Season 2 on at

    where did you write above code.

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

  • Community Member Profile Picture
    on at

    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
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    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);

  • Suggested answer
    Binesh Profile Picture
    7,885 on at

    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');

  • Community Member Profile Picture
    on at

    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
    Amol Salvi Profile Picture
    18,698 on at

    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

  • Suggested answer
    RockwithNav Profile Picture
    8,600 Super User 2025 Season 2 on at

    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. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans