Skip to main content

Sending emails To CC attachment in AX 2012 through X++ code

 Sending emails with CC and attachment in AX 2012 through X++

// Sending emails with CC and attachment in AX 2012



System administration --> Setup --> System --> E-mail parameters. to set the parameters


static void FromMailAX(Args _args)

{

    str                                  SendFrom    = 'Test@example.com';  // mail id of theSendFrom

    str                                   ToMailIds= 'test222@example.com';  //mulitple recipients can be specified

    str                                   cc          = 'abc@example.com';  // mulitple cc id's can be specified

    str                                   subject   = 'Subject of the mail';

    str                                   body      = 'Content of the mail';

    str                                   fileName = @'C:\Test.txt';  //Location of the attachment file


    List                                                       toList;

    List                                                       ccList;

    ListEnumerator                                     enumList;  

    Set                                                        permissionSet;

    System.Exception                                  exception;


    str                                                          mailServer;

    int                                                          mailServerPort;

    System.Net.Mail.SmtpClient                  mailClient;

    System.Net.Mail.MailMessage               mailMessage;

    System.Net.Mail.MailAddress                FromMail;

    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;

    ;


    try

    {

        toList = strSplit(recipient, ';');

        ccList = strSplit(cc, ';');

       

        permissionSet = new Set(Types::Class);

        permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

        permissionSet.add(new FileIOPermission(filename, 'test1'));

        CodeAccessPermission::assertMultiple(permissionSet);


        mailServer         = SysEmaiLParameters::find(false).SMTPRelayServerName;

        mailServerPort  = SysEmaiLParameters::find(false).SMTPPortNumber;

        mailClient          = new System.Net.Mail.SmtpClient(mailServer, mailServerPort);


        enumList = toList.getEnumerator();

        enumList.moveNext();

       

        FromMail      = new System.Net.Mail.MailAddress(sender);

        mailTo          = new System.Net.Mail.MailAddress(strLTrim(strRTrim(enumList.current())));

        mailMessage = new System.Net.Mail.MailMessage(FromMail, mailTo);

       

        mailToCollection = mailMessage.get_To();

        while (enumList.moveNext())

        {

            mailToCollection.Add(strLTrim(strRTrim(enumList.current())));

        }

       

        enumList                 = ccList.getEnumerator();

        mailCCCollection    = mailMessage.get_CC();

        while (enumList.moveNext())

        {

            mailCCCollection.Add(strLTrim(strRTrim(enumList.current())));

        }

       

        mailMessage.set_Priority(System.Net.Mail.MailPriority::High);

        mailMessage.set_Subject(subject);

        mailMessage.set_Body(body);


        mailAttachementCollection   = mailMessage.get_Attachments();

        mailAttachment              = new System.Net.Mail.Attachment(fileName);

        mailAttachementCollection.Add(mailAttachment);


        mailClient.Send(mailMessage);

        mailMessage.Dispose();


        CodeAccessPermission::revertAssert();


        info("Email sent successfully");

    }

    catch (Exception::CLRError)

    {

        exception = ClrInterop::getLastException();

        while (exception)

        {

            info(exception.get_Message());

            exception = exception.get_InnerException();

        }

        CodeAccessPermission::revertAssert();

    }


}

Popular posts from this blog

How to set up parent project in project accounting in ax 2012

create simple project and then go to the project hierarchy fast tab and there you must define sub-project ID format "-#" and then your sub-project will be enabled. For resource assigning in Project first you need to configure the HR module, in that you need to maintain the calendar for those employees and then you need to define the cost of that particular employee (for expense) and for Revenue you need to define the sales price of that particular employee. In the project accounting module you need to mention the calendar in scheduling fast tab and then you need to define WBS, in WBS activity you can be able to assign resources.

Sales order posting Error - Voucher do not balance as per date in axapta 2012

Problem - How to get rid of this error if its coming while doing the sales invoice . "The transactions on voucher V-00001 do not balance as per 4/11/2014. (accounting currency: -1111- reporting currency: -232) " .  Suggestions: 1.Exchange rate setup , number sequence of invoice voucher, currency rounding all are done correctly , but still this error exists 2.Define currency for each account..or go in currency setup and check currency and rounding up rules 3.Check with penny difference in GL 4.Check there is proper conversion exchange rate defined for reporting currencies. 5. Check Rounding of option of for primary and reporting currencies both. 6.Check all the posting accounts defined in Posting profiles 7.check COGS, Customer, issue, revenue accounts are mapped. 8.Check primary and reporting currency has proper exchange rates and rounding rules defined. 9.Try to increase the value in the penny difference and then post the sales invoice. 10. Make sure ...