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)

How to add Multiple attachments to email?

(0) ShareShare
ReportReport
Posted on by 433

Hi Experts,

 I am getting error while adding multiple attachments to email. i dont know even whether my code is correct or not.

The error is :

Microsoft Dynamics NAV
---------------------------

A call to System.Net.Mail.AttachmentCollection.Add failed with this message: Cannot access a disposed object.
Object name: 'System.Net.Mail.AttachmentCollection'.
---------------------------
OK
---------------------------


My code is:

----------------------------------------------------------------------------------------------------------------------

Repeat

Note:here i Have a code to run multiple reports from my Record Variable(SubmittedTimeSheetEntryL)

IF REPORT.SAVEASPDF(50053,FileNameL,SubmittedTimeSheetEntryL) THEN BEGIN //Saving Report 

MailAttachments := MailMessage.Attachments;
MailAttachment := MailAttachment.Attachment(FileNameL);//FilenameL is different for every report
MailAttachments.Add(MailAttachment);//Adding atttachements
MailMessage.IsBodyHtml := FALSE;

END;

UNtil Mycondition

First attachment is adding successfully but while loop comes to another attachment there it showing the above error.

-----------------------------------------------------------------------------------------------------------------------

Variable Declarations:

Name                       Datatype                sub type

MailAttachements  -  Dotnet               System.Net.Mail.AttachmentCollection.'System, Version=2.0.0.0,                                                                             Culture=neutral, PublicKeyToken=b77a5c561934e089'

MailAttachment     -   Dotnet             System.Net.Mail.Attachment.'System, Version=2.0.0.0, Culture=neutral,                                                                 PublicKeyToken=b77a5c561934e089'

MailMessage        -   Dotnet                System.Net.Mail.MailMessage.'System, Version=2.0.0.0, Culture=neutral,                                                              PublicKeyToken=b77a5c561934e089'

 

Can any one  help to resolve this.

 Help should be appreciate. 

Thank you 

Mahesh

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Suresh Kulla Profile Picture
    50,245 Super User 2025 Season 2 on at

    Have you tried using the standard SMTP Mail codeunit and the function AddAttachement to attache multiple documents ?

    Is there a reason you are using .net interop ?

  • Mahesh U Profile Picture
    433 on at

    Dear Suresh,

    Thanks For your Suggestion i have used SMTP Mail CodeUnit  now i am able to send mail with multiple attachments.

    Once again Thank you.

    Can you Clarify why the above code is not working if you know the concept of .net interop...

    Regards,

    Mahes U

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)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans