class EmailJob
{
public static void main(Args _args)
{
DocuRef docuRef;
DocuType docuType;
SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
Email toEmail;
Email fromEmail;
SysEmailSystemTable emailSystemTable = SysEmailSystemTable::find("WFEMAIL"); // system email template email id.
SysEmailMessageTable sysEmailMessageTable = SysEmailMessageTable::find(emailSystemTable.EmailId, emailSystemTable.DefaultLanguage);
try
{
FromEmail = emailSystemTable.SenderAddr;//"abc@3ELogistics.onmicrosoft.com";
toEmail = "to@gmail.com";
messageBuilder.setBody("Hello from D365", false);
messageBuilder.setSubject("Email Test from D365");
messageBuilder.addTo(toEmail);
// Note: not calling setFrom() defaults to the current user for SMTP client, whereas
// when sent to Outlook any setFrom() value will be ignored since profiles on the client are used
messageBuilder.setFrom(fromEmail);
while select docuRef
where docuRef.RefCompanyId == curExt()
&& docuRef.RefTableId == tableNum(CustInvoiceTable)
&& docuRef.RefRecId == 5637151326 // CustInvoiceTable.recId
Exists join docuType
where docuType.typeId == docuRef.TypeId
&& docuType.TypeGroup == docuTypeGroup::File
{
messageBuilder.addAttachment(DocumentManagement::getAttachmentStream(docuRef),docuRef.Name + '.pdf');
}
SysMailerFactory::sendInteractive(messageBuilder.getMessage());
// Try using sendNonInteractive method too
}
catch (Exception::Error)
{
throw error("@SYS33567");
}
}
}