web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Error in Email sending

(0) ShareShare
ReportReport
Posted on by 135

Hi all,

I have used the below code to send an email. when I am running the job getting a message as below and mail has not been received. I have checked the SMTP.

error-mail-sending.JPG

static boolean VMsendEmail()
{
SysEmailParameters parameters = SysEmailParameters::find();

System.Net.Mail.SmtpClient mailClient;
System.Net.Mail.MailMessage mailMessage;
System.Net.Mail.MailAddress mailFrom;
System.Net.Mail.MailAddress mailTo;
System.Net.Mail.MailAddressCollection mailToCollection;
System.Net.Mail.MailAddressCollection mailCCCollection;
System.Net.Mail.AttachmentCollection mailAttachementCollection;
System.Net.Mail.Attachment mailAttachment;
System.Net.NetworkCredential mailCredentials;
SysEmailTable sysemailtable;
Map mappings = new Map(Types::String, Types::String);
Enumerator en ;
System.Exception e;
List toList;
ListEnumerator le;
str em;


SMTPRelayServerName mailServer;
SMTPPortNumber mailPortNumber;
SMTPUserName mailUserName;
SMTPPassword mailPassword;

InteropPermission interopPermission;
;


try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();

if (parameters.SMTPRelayServerName)
{
mailServer = parameters.SMTPRelayServerName;
}
else
{
mailServer = parameters.SMTPServerIPAddress;
}

mailPortNumber = parameters.SMTPPortNumber;
mailUserName = parameters.SMTPUserName;
mailPassword = SysEmailParameters::password();
mailCredentials = new System.Net.NetworkCredential(mailUserName,mailPassword);


mailClient = new System.Net.Mail.SmtpClient(mailServer, mailPortNumber);
mailFrom = new System.Net.Mail.MailAddress(parameters.SMTPUserName); //fromAddress);


toList = strSplit("sivakumarm@stablesoft.in",';');
en = toList.getEnumerator();

while (en.moveNext())
{
em = en.current();

le = toList.getEnumerator();
le.moveNext();

mailTo = new System.Net.Mail.MailAddress(strLTrim(strRTrim(le.current())));
mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo);

mailToCollection = mailMessage.get_To();
}//msk
while(le.moveNext())
{
mailToCollection.Add(strLTrim(strRTrim(le.current())));
}


mailMessage.set_From(mailFrom);
mailMessage.set_ReplyTo(mailFrom);
mailMessage.set_Priority(System.Net.Mail.MailPriority::High);
mailMessage.set_Subject("Test Mail");
mailMessage.set_IsBodyHtml(true);
mailMessage.set_Body("Hi i am from ax");

mailClient.set_EnableSsl(true);
mailClient.set_UseDefaultCredentials(false);
mailClient.set_Credentials(mailCredentials);

mailClient.Send(mailMessage);

mailMessage.Dispose();

CodeAccessPermission::revertAssert();
info("Email has been send.");
return true;


}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();
while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
return false;
}
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You must provide a valid from and to address, and have to correctly set up your E-mail parameters.

    Also the user who is sending the e-mail within your domain must have a valid mail profile or should be able to authenticate with the Exchange server, which is not always created when you use service execution accounts.

    The from address should normally match the domain profile of your mail server. Is this an Exchange server within your organization, or Office365?

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi.

    Although this is probably not the case here, you may also want to check whether the server requires SSL encryption. The DLL you're using should have a parameter that you can set for this. Normally if the port is not port 25 the server is requiring some form of encryption

  • Vilmos Kintera Profile Picture
    46,149 on at

    If the answers above have resolved your issue, take your time to tick the checkbox next to the helpful posts to close the topic.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans