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 :

Email helper class to send email with attachment in Dynamics 365 finance and operations

Jayaprakash Reddy Profile Picture Jayaprakash Reddy 270

Its very basic need from customers to send email with attachments for any implementation projects, hope the below helper class will be useful in this case.

/// 

/// email helper class to send email with attachment

/// 

public class EmailHelperClass

{

    public static boolean sendEmail(str _fromEMail, str _toEmail, sysEmailSubject _subject, str _body, str _ccEmail = "", FileName _filename ="", System.IO.Stream _stream = null)

    {

        System.Exception exception;

        try

        {

            var messageBuilder = new SysMailerMessageBuilder();

            messageBuilder.addTo(_toEmail)

                    .setSubject(_subject)

                    .setBody(_body);

       

            if (_ccEmail)

            {

                messageBuilder.addCc(_ccEmail);

            }

            if (_fromEMail)

            {

                messageBuilder.setFrom(_fromEMail);

            }

       

            if (_stream != null)

            {

                messageBuilder.addAttachment(_stream,_filename);

            }

            SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());

        }

        catch (Exception::CLRError)

        {

            exception = CLRInterop::getLastException();

            info(strFmt("@SCM:EmailNotSentSetupInstruction", exception.ToString()));

        }

        return true;

    }

 

}

Hope this helps!, I will come with another interesting blog post!

Comments

*This post is locked for comments