Send email from dynamics ax
2015-09-17 12:11
453 查看
method1----------------------------------------------------
static void jay_testmail(Args _args)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;
;
if (parameters.SMTPRelayServerName)
{
relayServer = parameters.SMTPRelayServerName;
}
else
{
relayServer = parameters.SMTPServerIPAddress;
}
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = "Subject line for the email";
body = "<B>Body of the email</B>";
CodeAccessPermission::revertAssert();
try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress("xiangliqi@qq.com");
mailer.tos().appendAddress("jiaqiang@tps-logistics.com");
mailer.subject(subject);
mailer.htmlBody(body);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info("Email has been send!");
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info ("Failed to Send Email some Error occure");
}
}
method2-------------------------------------------------------
The most recommended way is to use the standard mail mechanism built in the system.
That way copies of any email you send will be save in the Email sending status form (based on tableSysOutgoingEmailTable) and you will be able to monitor and see status of sent emails:
This mechanism based on a system table that contain the emails, and a batch job that scan that table and send the emails, one by one (with retries and status controlling).
This technique is very simple to use and therefore it has some disadvantages; you cannot add attachments or use advanced email properties (cc, bcc, priority flag, etc).
To use this mechanism, first you have to make sure you a SMTP server configured and running.
Go to
Administration -> Setup -> E-mail parameters
and fill the required settings
Next step is to make sure the E-mail distributor batch is up and running.
Go to
Basic -> Inquiries -> Batch Job and check if the batch job exists with status ExecutingorWaiting.
static void testmail2(Args _args)
{
SysMailer mail;
SysOutgoingEmailTable outgoingEmailTable;
SysEmailItemId nextEmailItemId;
Map map;
str SenderName, SenderEmail, To, Subject, Body;
;
SenderName = "tps jiaqiang";
SenderEmail = "xiangliqi@qq.com";
To = "jiaqiang@tps-logistics.com";
Subject = "Subject line for the email";
Body = "<B>Body of the email</B>";
nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = SenderEmail;
outgoingEmailTable.SenderName = SenderName;
outgoingEmailTable.Recipient = To;
outgoingEmailTable.Subject = SysEmailMessage::stringExpand(Subject, map);
outgoingEmailTable.Priority = eMailPriority::Normal ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 0;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = Body;
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
info("xixi");
}
method3--------------------------------------------------------------------
通过AX邮件模板的定义发送邮件
static void jay_testmail3(Args _args)
{
str emailId = "JayEmail";
str language = "zh-hans";
str address = "jiaqiang@tps-logistics.com";
Map mappings = new Map(Types::String, Types::String);
;
mappings.insert("vendor", "lenovo");
SysEmailTable::sendMail(emailId, language, address, mappings, "", "", true, "jiaqiang");
info("xixi");
}
static void jay_testmail(Args _args)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;
;
if (parameters.SMTPRelayServerName)
{
relayServer = parameters.SMTPRelayServerName;
}
else
{
relayServer = parameters.SMTPServerIPAddress;
}
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = "Subject line for the email";
body = "<B>Body of the email</B>";
CodeAccessPermission::revertAssert();
try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress("xiangliqi@qq.com");
mailer.tos().appendAddress("jiaqiang@tps-logistics.com");
mailer.subject(subject);
mailer.htmlBody(body);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info("Email has been send!");
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info ("Failed to Send Email some Error occure");
}
}
method2-------------------------------------------------------
The most recommended way is to use the standard mail mechanism built in the system.
That way copies of any email you send will be save in the Email sending status form (based on tableSysOutgoingEmailTable) and you will be able to monitor and see status of sent emails:
This mechanism based on a system table that contain the emails, and a batch job that scan that table and send the emails, one by one (with retries and status controlling).
This technique is very simple to use and therefore it has some disadvantages; you cannot add attachments or use advanced email properties (cc, bcc, priority flag, etc).
To use this mechanism, first you have to make sure you a SMTP server configured and running.
Go to
Administration -> Setup -> E-mail parameters
and fill the required settings
Next step is to make sure the E-mail distributor batch is up and running.
Go to
Basic -> Inquiries -> Batch Job and check if the batch job exists with status ExecutingorWaiting.
static void testmail2(Args _args)
{
SysMailer mail;
SysOutgoingEmailTable outgoingEmailTable;
SysEmailItemId nextEmailItemId;
Map map;
str SenderName, SenderEmail, To, Subject, Body;
;
SenderName = "tps jiaqiang";
SenderEmail = "xiangliqi@qq.com";
To = "jiaqiang@tps-logistics.com";
Subject = "Subject line for the email";
Body = "<B>Body of the email</B>";
nextEmailItemId = EventInbox::nextEventId();
outgoingEmailTable.EmailItemId = nextEmailItemId;
outgoingEmailTable.IsSystemEmail = NoYes::No;
outgoingEmailTable.Sender = SenderEmail;
outgoingEmailTable.SenderName = SenderName;
outgoingEmailTable.Recipient = To;
outgoingEmailTable.Subject = SysEmailMessage::stringExpand(Subject, map);
outgoingEmailTable.Priority = eMailPriority::Normal ;
outgoingEmailTable.WithRetries = false;
outgoingEmailTable.RetryNum = 0;
outgoingEmailTable.UserId = curUserId();
outgoingEmailTable.Status = SysEmailStatus::Unsent;
outgoingEmailTable.Message = Body;
outgoingEmailTable.LatestStatusChangeDateTime = DateTimeUtil::getSystemDateTime();
outgoingEmailTable.insert();
info("xixi");
}
method3--------------------------------------------------------------------
通过AX邮件模板的定义发送邮件
static void jay_testmail3(Args _args)
{
str emailId = "JayEmail";
str language = "zh-hans";
str address = "jiaqiang@tps-logistics.com";
Map mappings = new Map(Types::String, Types::String);
;
mappings.insert("vendor", "lenovo");
SysEmailTable::sendMail(emailId, language, address, mappings, "", "", true, "jiaqiang");
info("xixi");
}
相关文章推荐
- LeetCode219:Contains Duplicate II
- ECSHOP后台SQL查询提示错误 this sql May contain UPDATE,DELETE,TRUNCATE,ALTER,DROP,FLUSH,INSERT
- 采用UltraISO制作U菜Win7安装盘,显现"File not find /BOOT/CDMENU.EZB.ezb"错误
- hdu 4750 Count The Pairs(并查集+二分)
- 深入理解mybaits数据源与连接池
- conversion to dalvik format failed with error 1。
- dig 命令 LINUX http://blog.csdn.net/zavens/article/details/3179121
- assign、retain、copy使用异同
- CF 579A Raising Bacteria
- leetcode:Contains Duplicate III
- AIX .tgz的安装包及登录日志查看
- Email正则表达式日常整理大全
- 使用Jmai发送邮件
- Container With Most Water 解答
- [CareerCup] 9.1 Climbing Staircase 爬楼梯
- cf#320 Div.2 Problem A Raising Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- rails s的时代一去不复返了
- Email正则表达式日常整理大全
- exchange email account最多只能在10个终端上设置