Sending mail to multiple person in to address

I need to send mail to multiple to address not CC/BCC.

Using SysMailer

-To address come from Table

Now i could send mail to only one person, using hardcore the mail address

Waiting for your reply

Thanks,

Jeevanandham

What does that mean? Can you please explain or show us the code?

static void SendEmail(Args _args)

{

SysEmailParameters parameters = SysEmailParameters::find();

SMTPRelayServerName relayServer;

SMTPPortNumber portNumber;

SMTPUserName userName;

SMTPPassword password;

Str1260 subject,body;

InteropPermission interopPermission;

SysMailer mailer;

System.Exception e;

OEMImportConfigurationTest OEM;

List toAddr;

ListEnumerator lenum;

str toAddress = OEM.Email;

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 = “Body of the email”;

CodeAccessPermission::revertAssert();

try

{

interopPermission = new InteropPermission(InteropKind::ComInterop);

interopPermission.assert();

mailer = new SysMailer();

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

//instantiate email

mailer.fromAddress(userName);

toAddr = SysEmailDistributor::splitEmail(OEM.Email);

lenum = toAddr.getEnumerator();

lenum.moveNext();

while(lenum.moveNext())

{

mailer.tos().appendAddress(lenum.current());

}

//mailer.tos().appendAddress();

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”);

}

}

Trying this code now but how to fetch to address from table

OEM.Email field consist the data like " abc@xy.com,asd@xy.com,sdf@xy.com "

from this data i need to split those three mail address and need to send mail for those three mailid

https://www.tech.alirazazaidi.com/sending-email-using-x-code-dynamics-ax-2012/

https://ievgensaxblog.wordpress.com/2016/06/11/ax-2012-sysemaildistributor-does-not-send-emails-to-multiply-recipients/

This two links i followed…

if you look at this method SysEmailDistributor::splitEmail, the splitter used is semi colon. You can use the code, but the splitter as comma.
emailAddresses = strSplit(_email, “,”);

Thanks kranthi, ill check and update

Below job is working fine with multiple ToAddress with attachments

static void SendEmail(Args _args)
{
SysMailer mailer;
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject,body;
InteropPermission interopPermission;

System.Exception e;

List toAddr;
ListEnumerator lenum;
str toAddress = “abc@xy.com,asd@xy.com,sdf@xy.com”;
str filePathName = @“C:\Path\filename.xlsx”;

if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = “Testing mail”;
body = “Body of the email”;

CodeAccessPermission::revertAssert();

try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
//instantiate email
mailer.fromAddress(userName);

toAddr = strSplit(toAddress,",");
lenum = toAddr.getEnumerator();

while(lenum.moveNext())
{
mailer.tos().appendAddress(lenum.current());
}

mailer.subject(subject);
mailer.htmlBody(body);
mailer.attachments().add(filePathName);
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 occur”);
}
}