Search results for 'SMTP Component'. 1 post(s) found.

  1. 2009/07/07 How to send email by TIdSMTP VCL ?
2009/07/07 15:52

How to send email by TIdSMTP VCL ?


TIdSMTP Component is very useful VCL in Delphi 2009. Here's the simple example to Send email.

uses IdSMTP, IdMessage;;

procedure KMAIL( sTo, title, body:string);
var
  IdMsg : TIdMessage;
begin
  IdMsg := TIdMessage.Create(nil);
  try
    with TIdSMTP.Create(nil) do
    try
      UserName := SMTPFrm.m_username.Text;
      Password := SMTPFrm.m_password.Text;
      Host := SMTPFrm.m_host.Text;
      IdMsg.Body.Add(body);
      IdMsg.Recipients.emailAddresses := sTo;
      IdMsg.Subject := title;
      IdMsg.From.Address := SMTPFRm.m_email.Text;
      IdMsg.From.Name := SMTPFRm.m_realname.Text;
      Connect;
      Send(IdMsg);
      Disconnect;
    finally
      Free;
    end;
  finally
    IdMsg.free;
  end;
end;

procedure TMainFrm.Button1Click(Sender: TObject);
begin
  KMAIL( 'foo@foo.com', 'Test mail from kurapa', 'Man, this is test mail from kurapa!!');
end;

As you can see above, you need Host, User ID, Password for sending email. In addition, you can define SMTP port as well.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.