Wednesday, January 5, 2011

Send Email with Delphi

Question/Problem/Abstract:
Here I am going to explain how we can send email through Gmail using Delphi 7 and Indy 9
Answer:


First of all you should have a Gmail account (It is free but you should be invited by someone);

In Delphi open a new application . On your form put these components


         - idSMTP1 (TidSMTP)
         - IdSSLIOHandlerSocket1 (TIdSSLIOHandlerSocket)
         - IdMessege1 (TIdMessage)
         - Memo1, Memo2, Memo3 (TMemo)
         - TButton


set the SMTP component properties as below:


  object IdSMTP1: TIdSMTP
    OnStatus = IdPOP31Status
    IOHandler = IdSSLIOHandlerSocket1
    MaxLineAction = maException
    Host = 'smtp.gmail.com'
    Port = 465
    AuthenticationType = atLogin
    Password = 'YourPassword'
    Username = 'YourUserName@gmail.com'
  end


and for the IdSSLIOHandlerSocket component:

  object IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket
    SSLOptions.Method = sslvSSLv2
    SSLOptions.Mode = sslmUnassigned
    SSLOptions.VerifyMode = []
    SSLOptions.VerifyDepth = 0
  end


in the SatatusInfo event of the IdSSLIOHandlerSocket1 Type:

    Memo3.Lines.Add('idSSL:  ' +Msg);


in the SatatusInfo event of the IdSSLIOHandlerSocket1 Type:

    Memo2.Lines.Add(AStatusText);

in the OnClick event of the Button1 component write:

  IdMessage1.From.Address := 'Yourmail address';
  IdMessage1.Recipients.EMailAddresses := 'Recipient mail address'

  IdMessage1.Subject := 'The Subject';
  IdMessage1.Body.Text := Memo1.Lines.Text;

  IdSMTP1.Connect();
  try
    IdSMTP1.Send(IdMessage1);
  finally
    IdSMTP1.Disconnect;
  end;

I have tested this application and it works fine
Hope you enjoy it...
you can design a good GUI to do the job...

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum