Tag: Email send

Email sending using file template

HI, below sample code used to send email using Email tempalte formate in multiple lines and header formate.

static void sendMail(Email _defEmail, SysEmailId _emailTemplate, PurchTable PurchTable)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject;
Notes msgbody ;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;

SysEmailTable table;
SysEmailMessageTable message;

str newMessageBody;

;

if(_defEmail)
{
if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;

portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();

table = SysEmailTable::find(_emailTemplate);
message = SysEmailMessageTable::find(table.EmailId, table.DefaultLanguage);
if (message)
{
newMessageBody = VendorSendEmail::renderLetter(message,PurchTable);
}
subject = message.Subject;
msgbody = newMessageBody;

CodeAccessPermission::revertAssert();

try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress(SysUserInfo::find().Email);
mailer.tos().appendAddress(_defEmail);
mailer.subject(subject);
mailer.htmlBody(msgbody);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info(“@CIT957”);
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();

while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info (“error”);
}
}
else
error(“done”);

}