Jump to content

Send HTML Email - Exchange - Threaded - Indy 10.5.8


Recommended Posts

Hi!

 

Complementing my sample about printing HTML from Dataset using UniURLFrame. For a basic reporting solution. Now I share a code to send the HTML using Indy, tested with version 10.5.8.

 

 

My other topic is (Dataset To HTML - Report):

http://forums.unigui.com/index.php?/topic/2696-dataset-to-html-report/

 

 

The code to send email is threaded and works with Exchange and Google servers.

May contain errors. Sorry. Use at your own risk.

 

How to use?

 

1) Download the pas file attached (the thread);

 

2) Download the precompiled OpenSSL libraries for your correct windows version 32/64 bits:

    Author:  Arvid Winkelsdorf, digivendo GmbH, www.digivendo.com
                  for The Indy Project, www.indyproject.org

    I have them here if anyone wants.

    Save the files libeay32.dll and ssleay32.dll inside the folder of your application.

 

3) Code like this to send an HTML email:

 

          ThdSM := TThdSendMail.Create;
          ThdSM.EmailData.edSMTPUserName := 'account@domain.com.br';
          ThdSM.EmailData.edSMTPPassword := 'myhiddenpassword';
          ThdSM.EmailData.edSMTPServer := 'theexchangeserver';
          ThdSM.EmailData.edSMTPPort := 587;
          ThdSM.EmailData.edSSLConnection := true;
          ThdSM.EmailData.edUseTLS := utUseExplicitTLS;
          ThdSM.EmailData.edSenderEmail := ThdSM.EmailData.edSMTPUserName;
          ThdSM.EmailData.edSenderApp := 'Sender Information';
          ThdSM.EmailData.edToEmail := 'recipient1,recipient2,recipient3';
          ThdSM.EmailData.edSubject := 'subject';
          ThdSM.EmailData.edBody.Text := ToHTML.HTML.Text; // THE HTML CONTENT
          ThdSM.EmailData.edPriority := mpNormal;
          ThdSM.EmailData.edTimeOut := 15000; // 15 segundos
          // run thread, send mail
          ThdSM.Start;

          // ThdSM.FreeOnTerminate is set true inside create, so we don't need to free here

 

 

Attention!!!!

 

Inside the ThdSendMail thread the code is currently configured to work with Exchange servers, to use google or other configurations you should change some properties like:

 

          SSLHandler.SSLOptions.Method := sslvTLSv1;
          SSLHandler.SSLOptions.Mode := sslmClient;

          and maybe port

 

But works with gmail too, tested. I just don't have the correct config now.

 

 

Bye!

 

Bruno


 

 

 

UnitThdSendMail.zip

  • Upvote 3
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...