How To Send An E-mail By Code

Use this function to send an e-mail through your program. You must have the component TNMSMTP from FastNet tools.
This component is included in Delphi 4-5 Professional and Enterprise

procedure TForm1.Button1Click(Sender: TObject);
begin
  NMSMTP1.Host := ‘mail.host.com’;
  NMSMTP1.UserID := ‘username’;
  NMSMTP1.Connect;

  NMSMTP1.PostMessage.FromAddress := ‘webmaster@swissdelphicenter.ch’;
  NMSMTP1.PostMessage.ToAddress.Text := ‘user@host.com’;
  NMSMTP1.PostMessage.Body.Text := ‘This is the message’;
  NMSMTP1.PostMessage.Subject := ‘Mail subject’;
  NMSMTP1.SendMail;
  showmessage(‘Mail sent !’);
end;

Leave a Reply

Your email address will not be published. Required fields are marked *