Send Mail through code

AX uses CDO.Message component to send a email and Here’s a example.
static void SendMailQuick(Args _args)
{
SysMailer   mailer;
;

mailer = new SysMailer();

mailer.quickSend(“david@dickiesmedical.com“, “david@dickiesmedical.com“, “test subject”, “test body”, “sjin@dickiesmedical.com“, “c:\\testfile.txt”);
}

or other way
before using this way you need to setup email parameters through Administration – Setup – E-mail parameters
static void sendMail(Args _args)
{
#SysMailer
#DEFINE.SenderName(‘David Park’)
#DEFINE.Sender(‘david@dickiesmedical’)
#DEFINE.Recipient(‘david@dickiesmedical.com’)
#DEFINE.Recipient2(‘sjin@dickiesmedical.com’)
#DEFINE.Subject(‘test mail subject’)
#DEFINE.MessageBody(‘test mail message body’)

SysMailer   mailer;
SysMailerAddressField   tos;

FileIOPermission fileIOPermission;
InteropPermission interopPermission;

str relayServer;
int portNumber;
str userName;
str password;
boolean NTLM;

str filePathName;
str tempPath;

SysEmailParameters parameters = SysEmailParameters::find();
;

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

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

//fileIOPermission = new FileIOPermission(”,’r’);
//fileIOPermission.assert();

//tempPath = WinAPIServer::getTempPath();

//CodeAccessPermission::revertAssert();

interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
CodeAccessPermission::revertAssert();

mailer.SMTPRelayServer(relayServer, portNumber, userName, password, NTLM);

mailer.fromAddress(#Sender,#SenderName);

tos = mailer.tos();
//tos.appendAddress(“david@dickiesmedical.com,sjin@dickiesmedical.com“);
tos.appendAddress(#Recipient);

mailer.priority(1);
mailer.subject(#Subject);
mailer.htmlBody(#MessageBody);

mailer.sendMail();
}

Or
If you are up and running E-mail distributor batch, then simple insert apropriate data into SysOutgoingEmailTable and SysOutgoingEmailData(Optional). batch will get the record from the table and try to send out.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: