Error in document sending thrugh Email

kmkaot
Member Posts: 261
Dear friends,
I am not getting results for sending a documents as attachment in email.
can you help please...
SMTPsetup.GET;
SenderName:=SMTPsetup."Email sender Name";
SenderAddress:=SMTPsetup."Email sender email";
Recipients:=vendorRec."E-Mail"+';'+SMTPsetup."Manager Email";
kSubject:="No."+' PO for '+FORMAT(Amount);
kBody:=' ';
Tofile := Name;
Tofile := "No."+'.pdf';
FileAndPathName := SMTPsetup."Path to Save Report" + Tofile;
FileAndPathName:=CONVERTSTR(FileAndPathName,'\','/');
FileName:=FileAndPathName;
WHILE STRPOS(FileName,'\') > 0 DO
FileName := COPYSTR(FileName, STRPOS(FileName,'\') +1);
CurrPage.SETSELECTIONFILTER(Rec);
REPORT.SAVEASPDF(405, FileName, Rec);
CLEAR(email);
email.CreateMessage(Recipients,'','',kSubject,kBody,FALSE,FALSE);
email.AddBodyline(' Dear Sir/Madam');
email.AddBodyline('<BR><BR>');
email.AddBodyline(' PO Document '+"No."+' '+"Pay-to Name"+' approved ');
email.AddBodyline('<BR><BR>');
email.AddBodyline('Operations');
email.AddBodyline('<BR><BR>');
email.AddBodyline('My Company');
email.AttachFile(FileName);
MESSAGE(FileName);
email.Send;
Pleasee..
kris
I am not getting results for sending a documents as attachment in email.
can you help please...
SMTPsetup.GET;
SenderName:=SMTPsetup."Email sender Name";
SenderAddress:=SMTPsetup."Email sender email";
Recipients:=vendorRec."E-Mail"+';'+SMTPsetup."Manager Email";
kSubject:="No."+' PO for '+FORMAT(Amount);
kBody:=' ';
Tofile := Name;
Tofile := "No."+'.pdf';
FileAndPathName := SMTPsetup."Path to Save Report" + Tofile;
FileAndPathName:=CONVERTSTR(FileAndPathName,'\','/');
FileName:=FileAndPathName;
WHILE STRPOS(FileName,'\') > 0 DO
FileName := COPYSTR(FileName, STRPOS(FileName,'\') +1);
CurrPage.SETSELECTIONFILTER(Rec);
REPORT.SAVEASPDF(405, FileName, Rec);
CLEAR(email);
email.CreateMessage(Recipients,'','',kSubject,kBody,FALSE,FALSE);
email.AddBodyline(' Dear Sir/Madam');
email.AddBodyline('<BR><BR>');
email.AddBodyline(' PO Document '+"No."+' '+"Pay-to Name"+' approved ');
email.AddBodyline('<BR><BR>');
email.AddBodyline('Operations');
email.AddBodyline('<BR><BR>');
email.AddBodyline('My Company');
email.AttachFile(FileName);
MESSAGE(FileName);
email.Send;
Pleasee..
kris
0
Answers
-
You did not get the VendorRec.
You have to do like
CLEAR(VendorRec);
VendorRec.SETCURRENTKEY("No.");
VendorRec.GET('some vendor');Best Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1 -
This code is already there. I did not show all.
Do we require MS outlook on Server
Warm regards
Krish0 -
Do we require MS outlook on Server
What do you do with the path? why do you first prepend it, then chop it off again before you use it?
Without a path, I do not know if SAVEASPDF and email.AttachFile assume the same path. better specify the path. Make sure that SMTPsetup."Path to Save Report" ends with a (back)slash.
Where did you look for results? Look in your outbox and in sent items.
Changing the ShowNewMailDialog parameter to true in email.CreateMessage while developping might also help to verify everything.0 -
Hi Kamkaot,
Which version of NAV are you using? I have developed a custom functionality of sending Email in batch for posted documents. I used the system generated path as follows. May be this could help you.
SendReport()
{
ServerAttachmentFilePath := GenerateReport(HeaderDoc,ReportID,CustomReportSelection);
SendAttachment(SalesDocumentNo,Customer."No.",ServerAttachmentFilePath,DocumentType,SendTo,CustomReportSelection);
}
GenerateReport()
{
IF CustomReportLayout.GET(CustomReportSelection."Custom Report Layout ID") THEN BEGIN
ReportLayoutSelection.SetTempLayoutSelected(CustomReportLayout.ID);
REPORT.RUNMODAL(CustomReportSelection."Report ID",NOT HideDialog,FALSE,HeaderDoc);
ReportLayoutSelection.SetTempLayoutSelected(0);
END ELSE
IF NOT REPORT.SAVEASPDF(ReportID,ServerAttachmentFilePath,HeaderDoc) THEN
ERROR(ServerSaveAsPdfFailedErr);
}Best Regards
Rehan Satti
Microsoft Dynamics NAV Technical Consultant
Please verify the answer if it satisfy your question. This will help other members of community.0 -
Thank you all.
I got the solution.
The file which was stored in server was not allowed to send from client system. we need to copy the same to client system first.
I have used file Managment CU to get the file
Thank you and warm regards
Kris0 -
You are welcomeBest Regards
Zohaib Ahmed
Dynamics NAV ERP Technical Consultant.
please like / agree / verify my answer, if it was helpful for you. thanks.1
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