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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested Answer

Send Email With attachement AX 2012

(0) ShareShare
ReportReport
Posted on by 384

Dear All,

i am trying to send an email with attachment, each time i click on menu item using below code, but the issue is that sometimes I GET THE FOLLOWING MESSAGE :Unable to read data from the transport connection: net_io_connectionclosed. or "Operation Timed Out"

 

public  void sendEmailv1(str _report)
{ SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
System.Net.Mail.MailAddress             mailFrom;
SMTPPassword password;
    System.Exception                      e;
    LogisticsAddressCountryRegionISOCode isoCountryCode;
Str subject,body,smtpserver;
    int                                     SMTPPort;
     System.Net.Mail.MailMessage             mailMessage;
    System.Net.Mail.SmtpClient              myMail;
    System.Net.Mail.MailAddressCollection   mailcoll;
    System.Net.Mail.MailAddress             mailTo;
    System.Net.Mail.MailAddress             mailCC;
    System.Net.Mail.Attachment         attachment;
    System.Net.Mail.AttachmentCollection        attachementCollection;
    InteropPermission interopPermission;
    Email                       requester;
    SysEmailId                  ApprovalEmailTemplate;
    SysEmailId                  ReopenEmailTemplate;
    int                         itemCount = 1;
    str                         ItemId, ItemQty, ItemDeliveryDate, ItemPrice;
    str                         companyDetails;
    FilenameOpen                attachmentFilename;

    Filename                        fileName = "Test.pdf";
    SrsReportRunController  ssrsController = new SrsReportRunController ();
    SRSPrintDestinationSettings     printerSettings;
    str                             ReportPath;
    date _fromdate,_todate;
    CustInvoiceJour custInvoiceJour;

    try
    {
    mailFrom            = new  System.Net.Mail.MailAddress(parameters.SMTPUserName ,"Admin");

relayServer = parameters.SMTPServerIPAddress;
portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();
subject = "Subject line for the email";
body = "Body of the email";

interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
  mailTo              = new  System.Net.Mail.MailAddress(xxxxx);
      smtpServer          = SysEmaiLParameters::find(false).SMTPRelayServerName;// using the SMTP server ip //setup in email Parameters
    mailMessage         = new System.Net.Mail.MailMessage(mailFrom,mailTo);

    mailmessage.set_Subject(subject);
    mailmessage.set_Body(body);
    attachementCollection  = mailMessage.get_Attachments();
    attachment = new System.Net.Mail.Attachment(_report); //file to attach
    attachementCollection.Add(attachment);
    SMTPPort            = SysEmaiLParameters::find(false).SMTPPortNumber;
    myMail              = new System.Net.Mail.SmtpClient(smtpServer, SMTPPort);
    myMail.set_EnableSsl(true);
    mymail.set_Credentials(New System.Net.NetworkCredential(parameters.SMTPUserName, password));
    mymail.Send(mailmessage);
    info('Email sent to ');
  mailMessage.Dispose();
   // myMail.Dispose();
    CodeAccessPermission::revertAssert();
}

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

I have the same question (0)
  • Suggested answer
    nunomaia Profile Picture
    25 Moderator on at

    If it's random error, is not related to attachment size or network connectivity ?

  • sylvesterPowerBi Profile Picture
    384 on at

    It was an issue related to SMTP settings

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 298 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 183 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 118 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans