SlideShare a Scribd company logo
1 of 2
static void TestEmail(Args _args)

{

    // Set these variables.

    str                                     sender = 'sender@somedomain.com';

    str                                     recipient =
'recipient@somedomain.com';

    str                                     cc1 = 'cc@somedomain.com';

    str                                     subject = 'Test';

    str                                     body = 'Test';

    str                                     fileName1 = @'C:test.txt';



    Set                                     permissionSet;

    System.Exception                        e;



    str                                     mailServer;

    System.Net.Mail.SmtpClient              mailClient;

    System.Net.Mail.MailMessage             mailMessage;

    System.Net.Mail.MailAddress             mailFrom;

    System.Net.Mail.MailAddress             mailTo;

    System.Net.Mail.MailAddressCollection mailCCCollection;

    System.Net.Mail.AttachmentCollection    mailAttachementCollection;

    System.Net.Mail.Attachment              mailAttachment;

    ;



    try

    {

          permissionSet = new Set(Types::Class);

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

          permissionSet.add(new FileIOPermission(filename1, 'rw'));

          CodeAccessPermission::assertMultiple(permissionSet);



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

          mailClient = new System.Net.Mail.SmtpClient(mailServer);
mailFrom = new System.Net.Mail.MailAddress(sender);

        mailTo   = new System.Net.Mail.MailAddress(recipient);

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

        mailCCCollection = mailMessage.get_CC();

        mailCCCollection.Add(cc1);

        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(fileName1);

        mailAttachementCollection.Add(mailAttachment);



        mailClient.Send(mailMessage);

        mailMessage.Dispose();



        CodeAccessPermission::revertAssert();



        info("Email sent.");

    }

    catch (Exception::CLRError)

    {

        e = ClrInterop::getLastException();

        while (e)

        {

            info(e.get_Message());

            e = e.get_InnerException();

        }

        CodeAccessPermission::revertAssert();

    }

}

More Related Content

What's hot

Pug - a compiler pipeline
Pug - a compiler pipelinePug - a compiler pipeline
Pug - a compiler pipelineForbes Lindesay
 
Codes
CodesCodes
CodesOSit3
 
Mule esb object_to_jackson_json
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_jsonDavide Rapacciuolo
 
Showdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennShowdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennJavaDayUA
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesCumulations Technologies
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesGennaro Spagnoli
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7Ananda Kumar HN
 
Converting with custom transformer part 2
Converting with custom transformer part 2Converting with custom transformer part 2
Converting with custom transformer part 2Anirban Sen Chowdhary
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformerF K
 
C++ course start
C++ course startC++ course start
C++ course startNet3lem
 
Mule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterMule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterRaffaela Vitiello
 

What's hot (14)

Pug - a compiler pipeline
Pug - a compiler pipelinePug - a compiler pipeline
Pug - a compiler pipeline
 
Codes
CodesCodes
Codes
 
Mule esb object_to_jackson_json
Mule esb object_to_jackson_jsonMule esb object_to_jackson_json
Mule esb object_to_jackson_json
 
Showdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp KrennShowdown of the Asserts by Philipp Krenn
Showdown of the Asserts by Philipp Krenn
 
Retrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations TechnologiesRetrofit Technology Overview by Cumulations Technologies
Retrofit Technology Overview by Cumulations Technologies
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutesMule esb How to convert from Object to Json in 5 minutes
Mule esb How to convert from Object to Json in 5 minutes
 
C++ prgms io file unit 7
C++ prgms io file unit 7C++ prgms io file unit 7
C++ prgms io file unit 7
 
minor final
minor finalminor final
minor final
 
Retro vs volley (2)
Retro vs volley (2)Retro vs volley (2)
Retro vs volley (2)
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
 
Converting with custom transformer part 2
Converting with custom transformer part 2Converting with custom transformer part 2
Converting with custom transformer part 2
 
Converting with custom transformer
Converting with custom transformerConverting with custom transformer
Converting with custom transformer
 
C++ course start
C++ course startC++ course start
C++ course start
 
Mule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converterMule esb How to use Jackson in Object to Json converter
Mule esb How to use Jackson in Object to Json converter
 

Viewers also liked

Dynamics AX 2012 R3 release is OUT!
Dynamics AX 2012 R3 release is OUT!Dynamics AX 2012 R3 release is OUT!
Dynamics AX 2012 R3 release is OUT!daisytvh
 
What's new with ADAX Retail Distribution?
What's new with ADAX Retail Distribution?What's new with ADAX Retail Distribution?
What's new with ADAX Retail Distribution?daisytvh
 
93016175 ax2012-enus-rep-02
93016175 ax2012-enus-rep-0293016175 ax2012-enus-rep-02
93016175 ax2012-enus-rep-02Ahmed Farag
 
Enterprise portal development cookbook
Enterprise portal development cookbookEnterprise portal development cookbook
Enterprise portal development cookbookAhmed Farag
 
Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Ahmed Farag
 
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Ahmed Farag
 
Developer's guide to customization
Developer's guide to customizationDeveloper's guide to customization
Developer's guide to customizationAhmed Farag
 
Retail headquarters releasenotes
Retail headquarters releasenotesRetail headquarters releasenotes
Retail headquarters releasenotesAhmed Farag
 
Xplusplus advancedcoursemanualv3.0 axapta
Xplusplus advancedcoursemanualv3.0 axaptaXplusplus advancedcoursemanualv3.0 axapta
Xplusplus advancedcoursemanualv3.0 axaptaAhmed Farag
 
Creating a retail store in ax 2012 retail
Creating a retail store in ax 2012 retailCreating a retail store in ax 2012 retail
Creating a retail store in ax 2012 retailAhmed Farag
 

Viewers also liked (11)

Dynamics AX 2012 R3 release is OUT!
Dynamics AX 2012 R3 release is OUT!Dynamics AX 2012 R3 release is OUT!
Dynamics AX 2012 R3 release is OUT!
 
What's new with ADAX Retail Distribution?
What's new with ADAX Retail Distribution?What's new with ADAX Retail Distribution?
What's new with ADAX Retail Distribution?
 
93016175 ax2012-enus-rep-02
93016175 ax2012-enus-rep-0293016175 ax2012-enus-rep-02
93016175 ax2012-enus-rep-02
 
Enterprise portal development cookbook
Enterprise portal development cookbookEnterprise portal development cookbook
Enterprise portal development cookbook
 
Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development Dynamics ax 2012 workflow development
Dynamics ax 2012 workflow development
 
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
Developing ssrs-reports-for-dynamics-ax-120402001948-phpapp01
 
Morph xit
Morph xitMorph xit
Morph xit
 
Developer's guide to customization
Developer's guide to customizationDeveloper's guide to customization
Developer's guide to customization
 
Retail headquarters releasenotes
Retail headquarters releasenotesRetail headquarters releasenotes
Retail headquarters releasenotes
 
Xplusplus advancedcoursemanualv3.0 axapta
Xplusplus advancedcoursemanualv3.0 axaptaXplusplus advancedcoursemanualv3.0 axapta
Xplusplus advancedcoursemanualv3.0 axapta
 
Creating a retail store in ax 2012 retail
Creating a retail store in ax 2012 retailCreating a retail store in ax 2012 retail
Creating a retail store in ax 2012 retail
 

Similar to Send email

Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfoliomichael_colon
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
JUnit and Mockito tips
JUnit and Mockito tipsJUnit and Mockito tips
JUnit and Mockito tipsKohei Nozaki
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)Binary Studio
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unitliminescence
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginnersishan0019
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#priya Nithya
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactorXiaojun REN
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 
2019-10-05 - Untangled - Voxxed days ticino
2019-10-05 - Untangled - Voxxed days ticino2019-10-05 - Untangled - Voxxed days ticino
2019-10-05 - Untangled - Voxxed days ticinoArnaud Bos
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical FileFahad Shaikh
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka codeMykhailo Kotsur
 

Similar to Send email (20)

Network security
Network securityNetwork security
Network security
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfolio
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Database security
Database securityDatabase security
Database security
 
JUnit and Mockito tips
JUnit and Mockito tipsJUnit and Mockito tips
JUnit and Mockito tips
 
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
Generics
GenericsGenerics
Generics
 
Java practice programs for beginners
Java practice programs for beginnersJava practice programs for beginners
Java practice programs for beginners
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#Creating a Name seperator Custom Control using C#
Creating a Name seperator Custom Control using C#
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
2019-10-05 - Untangled - Voxxed days ticino
2019-10-05 - Untangled - Voxxed days ticino2019-10-05 - Untangled - Voxxed days ticino
2019-10-05 - Untangled - Voxxed days ticino
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Advanced Java - Practical File
Advanced Java - Practical FileAdvanced Java - Practical File
Advanced Java - Practical File
 
Be smart when testing your Akka code
Be smart when testing your Akka codeBe smart when testing your Akka code
Be smart when testing your Akka code
 
Code
CodeCode
Code
 

More from Ahmed Farag

What's new in ax 2012 for retail
What's new in ax 2012 for retailWhat's new in ax 2012 for retail
What's new in ax 2012 for retailAhmed Farag
 
Call report from x++
Call report from x++Call report from x++
Call report from x++Ahmed Farag
 
Data structures and algorisms
Data structures and algorismsData structures and algorisms
Data structures and algorismsAhmed Farag
 
Retail store connect technical reference
Retail store connect technical referenceRetail store connect technical reference
Retail store connect technical referenceAhmed Farag
 
Retail pos technical reference
Retail pos technical referenceRetail pos technical reference
Retail pos technical referenceAhmed Farag
 

More from Ahmed Farag (6)

What's new in ax 2012 for retail
What's new in ax 2012 for retailWhat's new in ax 2012 for retail
What's new in ax 2012 for retail
 
Number seq
Number seqNumber seq
Number seq
 
Call report from x++
Call report from x++Call report from x++
Call report from x++
 
Data structures and algorisms
Data structures and algorismsData structures and algorisms
Data structures and algorisms
 
Retail store connect technical reference
Retail store connect technical referenceRetail store connect technical reference
Retail store connect technical reference
 
Retail pos technical reference
Retail pos technical referenceRetail pos technical reference
Retail pos technical reference
 

Send email

  • 1. static void TestEmail(Args _args) { // Set these variables. str sender = 'sender@somedomain.com'; str recipient = 'recipient@somedomain.com'; str cc1 = 'cc@somedomain.com'; str subject = 'Test'; str body = 'Test'; str fileName1 = @'C:test.txt'; Set permissionSet; System.Exception e; str mailServer; System.Net.Mail.SmtpClient mailClient; System.Net.Mail.MailMessage mailMessage; System.Net.Mail.MailAddress mailFrom; System.Net.Mail.MailAddress mailTo; System.Net.Mail.MailAddressCollection mailCCCollection; System.Net.Mail.AttachmentCollection mailAttachementCollection; System.Net.Mail.Attachment mailAttachment; ; try { permissionSet = new Set(Types::Class); permissionSet.add(new InteropPermission(InteropKind::ClrInterop)); permissionSet.add(new FileIOPermission(filename1, 'rw')); CodeAccessPermission::assertMultiple(permissionSet); mailServer = SysEmaiLParameters::find(false).SMTPRelayServerName; mailClient = new System.Net.Mail.SmtpClient(mailServer);
  • 2. mailFrom = new System.Net.Mail.MailAddress(sender); mailTo = new System.Net.Mail.MailAddress(recipient); mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo); mailCCCollection = mailMessage.get_CC(); mailCCCollection.Add(cc1); 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(fileName1); mailAttachementCollection.Add(mailAttachment); mailClient.Send(mailMessage); mailMessage.Dispose(); CodeAccessPermission::revertAssert(); info("Email sent."); } catch (Exception::CLRError) { e = ClrInterop::getLastException(); while (e) { info(e.get_Message()); e = e.get_InnerException(); } CodeAccessPermission::revertAssert(); } }