Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Send email example (Delphi 5, Indy9, Gmail)

1,314 views
Skip to first unread message

Harvey Brown

unread,
Sep 15, 2006, 7:10:54 PM9/15/06
to
In case this is useful to other newbies, here is working Delphi code for
sending email via Gmail (Delphi 5, Indy 9).

- need these componenets on the form
idMsgSend: TidMessage;
SMTP: TidSMTP
IdSSLIOhandlerSocket1: TidSSLIOhandlerSocket
IdAntifreeze1: TidAntifreeze
- files ssleay32.dll and libeay32.dll must be in the same folder as the
.exe file when it runs or in windows system. From
http://indy.fulgan.com/SSL/
- contents of email message are in msgMemo on entry
- other stuff in edit boxes beginning with "edit".

Procedure TmainForm.SendBtnClick(Sender: TObject);
var s: string;

begin {*** SendBtnClick ***}
with IdMsgSend do
begin
Body.Assign(msgMemo.Lines);
From.Text := editReturnAddress;
ReplyTo.EMailAddresses := editReturnAddress
Recipients.EMailAddresses := editEmailAddress;
Subject := editSubject;
ReceiptRecipient.Text := '';
end;
{--- SMTP settings ---}
If thePassword = '' then SMTP.AuthenticationType := atNone
else SMTP.AuthenticationType := atLogin;
{extract username from the emailaddress}
s := editEmailAddress; i := pos('@',s); s := copy(s,1,i-1);
SMTP.Username := s;
SMTP.Password := editPassword;
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 465; {normally 25, but 465 for gmail}
if cboxUseSSL.checked then
begin
SMTP.IOHandler := idSSLIOHandlerSocket1;
smtp.authenticationtype := atlogin;
end;

{-- send the message --}
SMTP.Connect;
try
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
end;

This seems to work reliably under Windows XP home and pro.
As I understand it, SSL stops someone in the middle from reading the
message and assures your computer that it's ACTUALLY talking to Google.
Google sends you a message encrypted with their secret key, which only
they know. They might also encrypt it with your public key, so only you
can read it. You can decrypt it with Google's public key, which is
certified by some trusted source and distributed publicly (in the SSL
component?). So you can read Google's messages and you're guaranteed
they're from Google. They probably send you some identification string
in that message too. Now you reply, encrypting your message with
Google's public key and including the identification string. Only
Google can decrypt your message, using their secret key.

Thanks for the help from other posts on this forum.

Harvey (harvey at softwarespirit.com)

Riki Wiki

unread,
Sep 17, 2006, 6:34:41 AM9/17/06
to
Hoi Harvey

Good work but you need to repost your message on the Borland news server to
make everybody see it.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>

0 new messages