SEND EMAIL IN D365 CODE X++ LOGIC
public static void SendEmail()
{
System.IO.Stream workbookStream = new System.IO.MemoryStream();
SysMailerSMTP mailer = new SysMailerSMTP();
SysMailerMessageBuilder builder = new SysMailerMessageBuilder();
SysEmailParameters parameters = SysEmailParameters::find();
;
//you will have to setup the below parameters in sysadmin module
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.SMTPUseNTLM);
}
else
{
warning(“SERVER NOT FOUND”);
}
builder.setFrom(SysEmailParameters::find().SMTPUserName);
builder.addTo(“To address”);
builder.addCc(“CC address”);
builder.addAttachmentFromFile(“Fetch the file from the path”);
builder.setSubject(“Email subjectl”);
SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());
}
No comments:
Post a Comment