Send Email from D365FO using X++.
/// <summary>
/// SenMail alert
/// </summary>
/// <param name = "_emailTo">To email id</param>
/// <param name = "_Subject">email subject line</param>
/// <param name = "_body">email body text</param>
public void SendEmail(Description _emailTo, Description _Subject, ErErrorDescription _body)
{
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(_emailTo);
builder.setSubject(_Subject);
builder.setBody(_body);
SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());
}
No comments:
Post a Comment