November 8, 2006

My Tips: Indy and GMail

A practical Delphi tip: how to send email to/from GMail using Indy.

In the last year, I've moved a lot of my mail to GMail, although I still run my mail server in the Office. Now, beside my marco.cantu GMail account, I've started to move entire mail domains to GMail, using Google hosted services (very interesting, imho). The trouble is, however, that I have many client programs and web site applications that send mail, so if I want to get rid of my mail server I need to be able to send mail to GMail.

This was not terribly difficult, half-an-hour of research and coding, but not trivial either, as GMail requires you to use SSL for sending email. As Indy has full support for this technology (including TLS, which is what GMail prefers to use), it was only a matter of setting the proper parameters. I found many newsgroup posts, but none had the complete "ready-to-use" code. So I published it in a tip on my web site: Send mail to GMail using Indy.

I don't know if I'll be able to resume publishing coding tips like this on a regular basis, but in any case I've opened a new section on my web site (hosting technical tips with code in a blog is something I don't particularly like). We'll see if/how this evolves.



My Tips: Indy and GMail 

SSH or SSL? 
Comment by Anonymous on November 8, 12:57

My Tips: Indy and GMail 

Hi Marco.

If I was you, I'd make my own mailserver act as a
proxy for GMail, that whay you don't need to change
your code while still taking full advantage of GMail.


Comment by Andrea Raimondi on November 8, 16:07

My Tips: Indy and GMail 

Deinitely SSL.

SSH is the Secure SHell implementation, it can use 
encryption technologies from SSL.

Gmail (and many others) use POP3 over SSL using port 
995 to fetch mail, and SMTP over SSL using port 465 
to send mail.
Comment by Jeroen Pluimers [] on November 11, 11:13


Fixed. Thanks.
Comment by Marco Cantù [] on November 11, 14:16

My Tips: Indy and GMail 

 Hi Marco,
maybe you'd have to remind not to forget having 
installed SSL dll's for Indy.
I thus advise readers go to, then 
download +install the lacking dll's.
Comment by didier cabalé [] on December 15, 13:07

My Tips: Indy and GMail 

Hi Marco, 
Thank you very much for this example.
It is great.This was what I needed.
Comment by konstantin lalkovski on January 10, 14:51

My Tips: Indy and GMail 

 Hi marco:
   I did the same thing just as you mentioned. But 

when I executed my program, an error 

occured:'Credentials Rejected 7sm8437100nz0', I don't

know why? Can you help me solve this problem, I am 

very appreciate of you!! I am Chinese ,and my English

is poor ,so I hope you can understand what I said.

My EMailAddress is :
Comment by Yingzhuo Zhang on February 6, 13:29

My Tips: Indy and GMail 

 i have the same prob i cant send an email with the
example u provide any help would be appreciate ;)
Comment by Moussa on February 26, 14:06

My Tips Indy and GMail 

You guys need to go into gmail, and click on the 
settings options. Then go to the forwarding and pop3 
table, and enable pop3 forwarding on your gmail 

The ability to remotely access your mail via pop3 is 
not enabled by default, and this will cause a 
connection refusal message like the one you two are 
Comment by Foster on March 18, 02:51

My Tips Indy and GMail 

 Hi readers,
be aware that SSLv2 is no longer supported by gmail 
since march 11th 2010.
As a workaround, use SSLv3.
Practically, the change must be done in 
TIdSSLIOHandlerSocketOpenSSL, property SSLOptions > 
Method -> sslvSSLv3.
Hope it helps
Comment by didier cabalé [] on June 16, 16:17

Sending email with Delphi 7 and Indy 10 via GMAIL 

Hi all

Has anyone got some tips on sending email with indy 
10 (currently using 10.0.52) and SSL (currently 
trying via GMAIL?

I am using port 587, explicitTLS and sslvSSLv3 but 
keep on getting 

Could not load SSL 

and then  

ERROR: Socket Error # 10054
Connection reset by peer.

I've read all the forums and tried different 
combinations, but nothing helps! I have other 
programs that use my currnet version of Indy, so 
downgrading isn't an option.

Comment by Ulricke on October 24, 12:02

My Tips Indy and GMail 

Hi, Ulricke, try to set to SSLOptions.Mode := 
sslmUnassigned; instead of explicitTLS;
Comment by Renato Guarilha on December 13, 21:59

My Tips Indy and GMail 


I found this article and it's very helpful, but I'm
trying to translate your code into C++ for Builder
rather than Delphi, and I have got all of it done
except for this line:

SASLMechanisms = <>

I have no idea what that does or how to translate it
properly into C++. Help! 
Comment by Isac on December 21, 23:03

My Tips Indy and GMail - indy 10 sasl. 

This stuff is slightly out of date now that Indy10 has a 
new SASL based authentication plugin system.  It will 
work, provided that you add the SASL components.

A full downloadable ZIP of a demo of this would be 
great. If you don't have time to do it, I'll do it at my 

Comment by Warren Postma [] on August 3, 17:50

Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.