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
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.
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
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
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');
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);
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
where did you write above code.
please check whether salesheader is not deleted by the time above code is executed.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156