17 January 2013

Send an Email in AX / Email and alerts

Step 1. Admin-> setup->Email parameters
Step 2. Basic email template

SysEmail Errors please click here

static void sendEmail()
{
SysMailer mailer = new SysMailer();
SysEmailParameters parameters = SysEmailParameters::find();
str emailFrom = "abc@gmailcl.com";//sysuserInfo::find(curUserId(),false).Email;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
str _emailTo;
str _subject;
str _bodyText;
;
_emailTo = "xyz@gmail.com";
_subject = "Mail";
_bodyText = "Aboutn Report";
CodeAccessPermission::revertAssert();
permission.assert();
if (_emailTo != "")
{
if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
mailer.fromAddress(emailFrom);
mailer.tos().appendAddress(_emailTo);
mailer.subject(_subject);
mailer.htmlBody(_bodyText);
mailer.sendMail();
//SysInEtMail::sendEMail("Admin","En-us","abc@outlook.com"); // to email id
}
CodeAccessPermission::revertAssert();
}
==============================================
==============================================
static void emailThruSysMailer(Args _args)
{
SysMailer mailer = new SysMailer();
SysEmailParameters parameters = SysEmailParameters::find();
;

if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}



mailer.fromAddress('xxx@123.com');
mailer.tos().appendAddress('aaa@123.com');
mailer.subject('AZZZ');
mailer.htmlBody('Comunicazione AX');


mailer.sendMail();
}

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...