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 AX (Archived)

Attaching Multiple attachments in Email

(0) ShareShare
ReportReport
Posted on by 160

Hello,

Is it possible to attach multiple attachments in an email, the email is sent through a custom class using SysInetMail, the first attachment works absolutely fine but if I add a second one through code, it overlaps the first one. Any solutions ?

Help Much Appreciated.

-AK

*This post is locked for comments

I have the same question (0)
  • Otavio Anaga Profile Picture
    216 on at

    Can you put your code here?

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Abdul Khaliq,

    It's better to use SysMailerNet.quickSend() method where you can specify multiple attachments.

  • AbdulKhaliq Profile Picture
    160 on at

    Hi ievgen,

    Thanks for the response, I am currently using SysINetMail.sendMailAttachEx() but I don't know why its inconsistent as it does attach multiple files a few times but overwrites the first attachment sometimes. Following is the line where I tries to add my second attachment,

    4428.Untitled.png

    Thanks in advance,

    AK

  • Mea_ Profile Picture
    60,284 on at

    To find a sample of usage of anything in AX you can use cross-references . It will give you more than one example.

    Also you can post your code here and we could help you with it.

  • AbdulKhaliq Profile Picture
    160 on at

    I am just passing an extra parameter containing filePath of my second attachment and using a single line of code just to add it to the mail.

    boolean sendMailAttachEx(str     _toName,

                       str     _ccName,

                       str     _subject,

                       str     _text,

                       boolean _dialog,

                       str     _attachPath,

                       str     _ksAttachPath = '',

                       str     _attachName = '',

                       boolean _isHTML = false)

    {

       boolean result = false;

       smmOutlookEMail outlookEmail = new smmOutlookEMail();

       str folderPath, fullPath = _attachPath,

       ksFullPath = _ksAttachPath;//KS

       if (outlookEmail.createMailItem())

       {

           outlookEmail.parmEmailTos(_toName);

           outlookEmail.parmEmailCcs(_ccName);

           outlookEmail.addSubject(_subject);

           outlookEmail.isHTML(_isHTML);

           if (_mapiSetup.SignatureNoYes != Signature::Never)

           {

               _text = _text + '\n\n' + _mapiSetup.Signature;

           }

           outlookEmail.addBodyText(_text);

           if (_attachName)

           {

               folderPath = System.IO.Path::GetDirectoryName(_attachPath);

               fullPath = System.IO.Path::Combine(folderPath, _attachName);

               if (System.IO.File::Exists(fullPath))

               {

                   System.IO.File::Delete(fullPath);

               }

               System.IO.File::Move(_attachPath, fullPath);

           }

           outlookEmail.addFileAsAttachment(fullPath);

           outlookEmail.addFileAsAttachment(KSfullPath);//KS

           outlookEmail.sendEMail(smmSaveCopyOfEMail::No, _dialog);

           result = true;

       }

       return result;

    }  

  • Mea_ Profile Picture
    60,284 on at

    There is second parameter of addFileAsAttachment method and it is called "_position", did you try to change it from default value 1 ? Something like

    outlookEmail.addFileAsAttachment(fullPath);
    outlookEmail.addFileAsAttachment(KSfullPath, 2);
  • AbdulKhaliq Profile Picture
    160 on at

    Thanks a ton ievgen, looks correct :)

  • AbdulKhaliq Profile Picture
    160 on at

    It worked the first time but doing the same overwriting now again..

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans