2010. március 16., kedd

How to send mail in HTML format from a Delphi application


I would like to create a program which is able to send mail in HTML format. I tested some code but got a 'Connection Failed' message when I attempted to send the mail.


You may have to logon to the smtp server via Pop3 first:

  oLogon: TNMPop3;
  oMail: TNMSmtp;
  oLogon := TNMPop3.Create(self);
    with oLogon do
      Host := 'pop.mail.yahoo.com';
      UserID := 'user';
      Password := 'password';
  oMail := TNMSmtp.Create(self);
  with oMail do
      Host := 'smtp.mail.yahoo.com';
      Port := 25;
      UserID := 'YourID';
      SubType := mtHTML;
      { set all other properties, e. g. FromName, FromAddress, ReplyTo, Subject, etc }
      PostMessage.FromAddress := 'yourname@yahoo.com';
      PostMessage.FromName := 'YourName';
      PostMessage.Subject := 'My First HTML mail';
      {Replace [ ] brackets in the following three lines with < > ones}
      PostMessage.Body.Add('[html] [head] [/head]');
      PostMessage.Body.Add('[body] [h1]My 1st html msg[/h1] [/body]');

Nincsenek megjegyzések:

Megjegyzés küldése