SMTP Mail codeunit with SAVEASPDF

Alex_Chow
Member Posts: 5,063
Hi,
I've created a process to automatically send an e-mail to each customer ship-to. The e-mail also has a report that I've created using the SAVEASPDF function so the report can be sent as an attachment.
I can send the e-mail without problems, but I can't attach the pdf file. The code I have written so far is:
The ReportHelper codeunit is from Claus' blog found here:
http://blogs.msdn.com/b/nav-reporting/a ... -2009.aspx
I checked codeunit 397 (Mail) that the blog is using. It seems to convert the link to the file with this code in the codeunit:
Does anyone know how I can add the attachment using SAVEASPDF using the SMTP Mail (codeunit 400) codeunit?
I've created a process to automatically send an e-mail to each customer ship-to. The e-mail also has a report that I've created using the SAVEASPDF function so the report can be sent as an attachment.
I can send the e-mail without problems, but I can't attach the pdf file. The code I have written so far is:
ToFile := DELCHR(ShiptoAddress."Customer No." + FORMAT(WORKDATE),'=','/\:.,') + '.pdf'; FileName := TEMPORARYPATH + ToFile; REPORT.SAVEASPDF(REPORT::"My Report",FileName,ShiptoAddress); ToFile := ReportHelper.DownloadToClientFileName(FileName, ToFile); <The code to write the send to, body, etc> Mail.AddAttachment(ToFile); Mail.Send();
The ReportHelper codeunit is from Claus' blog found here:
http://blogs.msdn.com/b/nav-reporting/a ... -2009.aspx
I checked codeunit 397 (Mail) that the blog is using. It seems to convert the link to the file with this code in the codeunit:
IF AttachFileName <> '' THEN BEGIN BSTRConverterAttachFileName.ResetBSTR; BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileName); OAttachments := OSendMail.Attachments; OAttachment := OAttachments.Add(BSTRConverterAttachFileName); END;
Does anyone know how I can add the attachment using SAVEASPDF using the SMTP Mail (codeunit 400) codeunit?
Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
0
Answers
-
I thought the SMTP automation is created at server, so you don't need to upload the pdf file. do everything at the server.0
-
ara3n wrote:I thought the SMTP automation is created at server, so you don't need to upload the pdf file. do everything at the server.
So do you mean:ToFile := DELCHR(ShiptoAddress."Customer No." + FORMAT(WORKDATE),'=','/\:.,') + '.pdf'; FileName := TEMPORARYPATH + ToFile; REPORT.SAVEASPDF(REPORT::"My Report",FileName,ShiptoAddress); <The code to write the send to, body, etc> Mail.AddAttachment(FileName); Mail.Send();
Something like that?Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
Hmm... Doing that, I get the error saying that the caller does not have permission or the folder is read only.
Any suggestions?Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
Give the service tier permission to the temp path, or make the user a local admin.0
-
ara3n wrote:Give the service tier permission to the temp path, or make the user a local admin.
For a Dynamics NAV MVP, you're pretty smart!Confessions of a Dynamics NAV Consultant = my blog
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book0 -
hmmmm.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