How To…Customize Indy Email Settings

Question

“How do I customize the TIdIndy settings to connect to a secure email server such as Gmail?”

 

Solution

Note: Starting with ReportBuilder 19, it is possible to skip the steps below and simply set the TppSMTPIndy.UseTLS property to True. It is still necessary to download and copy the proper SSL .dll files for this feature to function (link below). See the help topic for TppSMTPIndy for more information.

Note: Some email services may require a separate setting or password to allow emailing from an outside application.

The TppSMTPIndy plugin gives access to the TIdSMTP object with the IndySMTP property. From there you can customize the TIdSMTP settings to connect to virtually any email server available.

To gain access to the IndySMTP property simply typecast the TppEmail.SMTP property as a TppSMTPIndy object…

Connecting to Gmail

Gmail requires TLS encryption from port 587 to send email from its server. To connect to the Gmail server with Indy components, you need to create a SSL IOHandler (TIdSSLIOHandlerSocketOpenSSL) to manage the encrypted connection.

Indy makes use of the OpenSSL libraries to connect to a SSL server. These libraries need to be installed on your machine before using the IOHandler. The latest OpenSSL libraries can be downloaded from the following web site…

http://indy.fulgan.com/SSL/

Once you download, simply copy the .dll files into your WINSYS\ directory or in your application path. As a rule of thumb, it is always a good idea to have the latest version of Indy and the OpenSSL libraries on your machine.

Below is an example of how you might send a report using Indy and Gmail.

Download: IndyGmail.zip

Sample Delphi code: