Sunday, January 17, 2021

Email via code in D365 F&O

In this post, We will be writing code to send mail via code:


 System.IO.Stream workbookStream = new System.IO.MemoryStream();

SysMailerSMTP   mailer = new SysMailerSMTP();

SysMailerMessageBuilder builder = new SysMailerMessageBuilder();

SysEmailParameters parameters = SysEmailParameters::find();

        

if (parameters.SMTPRelayServerName)

{

                mailer.SMTPRelayServer(parameters.SMTPRelayServerName,

                parameters.SMTPPortNumber,

                parameters.SMTPUserName,

                SysEmailParameters::password(),

                parameters.SMTPUseNTLM);

}

else

{

    warning("SERVER NOT FOUND");

}


builder.setFrom("atul.yadav@tectreeconsulting.com");

builder.addTo("atul.yadav@tectreeconsulting.com");

builder.setSubject("Subject of the Mail");

builder.setBody("This is the body of the mail");

SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());