我试图根据用户在其客户端触发的某些事件发送电子邮件。我不希望从客户端发送电子邮件(因为这需要我们几乎允许域中的每个工作站使用SMTP服务),而是从AOS服务器发出。从AOS服务器发送电子邮件
我想创建一个类将扩展RunBaseBatch
并在其中使用SysMailer
。
这是我到目前为止。
class Batch_Mailer extends RunBaseBatch
{
str subject;
str body;
str fromName;
str fromAddress;
str toAddress;
str smtpServer;
void new(str _subject, str _body, str _fromName, str _fromAddress, str _toAddress)
{
subject = _subject;
body = _body;
fromName = _fromName;
fromAddress = _fromAddress;
toAddress = _toAddress;
smtpServer = 'mail.domain.ca';
super();
}
public boolean canGoBatchJournal()
{
return true;
}
public void run()
{
SysMailer mail;
;
super();
try
{
mail = new SysMailer();
mail.fromAddress(fromAddress, fromName);
mail.SMTPRelayServer(smtpServer);
mail.tos().appendAddress(toAddress);
mail.htmlBody(strfmt(body));
mail.subject(subject);
mail.sendMail();
}
catch
{
//Log something maybe, but nice if the infolog would not pop up...
}
}
}
下面是我如何使用它:
Batch_Mailer mail;
mail = new Batch_Mailer("Subject.", strfmt("@VDX488", vendTable.AccountNum, curUserId()), "AX Alerts",
"[email protected]", "[email protected]"
不幸的是,这似乎是在客户端运行。如果我在启用了AOS服务器的开发盒虚拟机上运行代码(可以使用SMTP服务),则会触发电子邮件,但如果我在物理盒上的客户端中运行它(不允许使用SMTP服务)。
我想延长RunBaseBatch
和覆盖run
会做到这一点,但显然不是。有任何想法吗 ?
我也想知道如果这种方法会失败,因为我不认为大多数用户可以使用他们的帐户运行批处理......也许我将不得不使用模拟?
谢谢!
感谢。我认为我需要使用类似于'RunAsPermission'的东西,因为即使与具有相当多访问系统的用户一起运行此代码,我也会收到类似'请求InteropPermission'类型权限的错误。' –
这解决了它的问题:http://dynamics-ax-live.blogspot.ca/2009/09/error-request-for-permission-of-type.html –