Email Attachment

fazlehasan
Member Posts: 70
Our customer is using BC23.1
When I am trying to send an email with attachment (PDF), I am getting this error
"The Tenant Media does not exist. Identification fields and values: ID='{00000000-0000-0000-0000-000000000000}"
The error is generated in this line when I do the attachment:
EmailMsg.AddAttachment(FileNameForEmail, 'application/pdf', iStr);
where, iStrm is a variable of Type InStream;
I checked iStr has value,
and its generated from a BC Report,
oStrm := tempBlobcu.CreateOutStream();
if CustomerStatement.SaveAs('', ReportFormat::Pdf, oStrm) then begin
iStrm := tempBlobcu.CreateInStream();
Any suggestion would be appreciated.
Thanks.
When I am trying to send an email with attachment (PDF), I am getting this error
"The Tenant Media does not exist. Identification fields and values: ID='{00000000-0000-0000-0000-000000000000}"
The error is generated in this line when I do the attachment:
EmailMsg.AddAttachment(FileNameForEmail, 'application/pdf', iStr);
where, iStrm is a variable of Type InStream;
I checked iStr has value,
and its generated from a BC Report,
oStrm := tempBlobcu.CreateOutStream();
if CustomerStatement.SaveAs('', ReportFormat::Pdf, oStrm) then begin
iStrm := tempBlobcu.CreateInStream();
Any suggestion would be appreciated.
Thanks.
0
Answers
-
Hi, there's another thread that might help you. It has an accepted solution in it. It seems that the method utilized in that answer is to actually take the Blob InStream and convert it to Base64, and then use the SendMessage signature with the Base64 parameter.
https://forum.mibuso.com/discussion/76181/save-report-as-pdf-and-send-as-e-mail
Good luck!Marcelo Borges
D365 Business Central Solutions Architect
BC AL/NAV C/AL Developer
BC Repositories.com1 -
@markborges Thanks for your response!
I tried the solution, I am now getting a different error.
This time the error is:
Microsoft.Dynamics.Nav.Runtime.NavInStream variable not initialized.
This error occurred when I tried to convert the iStream.
txtB64 := converter_.ToBase64(iStr, true);
EmailMsg.AddAttachment(FileNameForEmail, 'application/pdf', txtB64);0 -
Hi @fazlehasan , can you share a bit more of your code? I need to see what type of initialization you have done prior to the faulty line.Marcelo Borges
D365 Business Central Solutions Architect
BC AL/NAV C/AL Developer
BC Repositories.com0 -
Thanks, I have looked back and found that I used a wrong variable for Initialization.
oStrm := tempBlobcu.CreateOutStream();
if CustomerStatement.SaveAs('', ReportFormat::Pdf, oStrm) then begin
iStrm := tempBlobcu.CreateInStream();
After correcting this, now I am back to this error:
The Tenant Media does not exist. Identification fields and values: ID='{00000000-0000-0000-0000-000000000000}'
Is there any extension that Business Central Require to do attachments or for handling Media? or is there any specific configuration related to email attachments?
Thanks.0 -
I found out my mistake,
I was doing this before creating the Email.
oStrm := tempBlobcu.CreateOutStream();
if CustomerStatement.SaveAs('', ReportFormat::Pdf, oStrm) then begin
iStrm := tempBlobcu.CreateInStream();
gtFileName := FileMgt.InstreamExportToServerFile(iStrm, 'PDF');
and that initialized the value of iStrm (I guess).
After Commenting this line, the attachment started working.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