要求发送的邮件内容是HTML格式而不是文本格式的,请问用什么控件可以实现!

解决方案 »

  1.   

    http://www.mwestern.com/delphi_example.htmunit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, MWesternLib_TLB;type
      TForm1 = class(TForm)
        Label1: TLabel;
        From: TEdit;
        Label4: TLabel;
        Label5: TLabel;
        ToName: TEdit;
        Label6: TLabel;
        ToAddress: TEdit;
        SendMail: TButton;
        Label7: TLabel;
        Body: TMemo;
        SendWebPage: TButton;
        SendHtmlComplete: TButton;
        Label8: TLabel;
        WebUrl: TEdit;
        Label9: TLabel;
        HtmlFile: TEdit;
        Label10: TLabel;
        Subject: TEdit;
        Status: TLabel;
        procedure SendMailClick(Sender: TObject);
        procedure SendWebPageClick(Sender: TObject);
        procedure SendHtmlCompleteClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}// Delphi example to send a simple plain-text Western email.
    procedure TForm1.SendMailClick(Sender: TObject);
    var
      mail: IMWestern;
    begin
      Status.Caption := 'Sending...';
      Status.Refresh();  mail := CoMWestern.Create();  // Unlock the component and point to the SMTP server.
      mail.UnlockComponent('unlockCode');
      mail.SmtpHost := 'smtp.earthlink.net';  // Set email header fields.
      mail.AddHeaderField('From',From.Text);
      mail.AddRecipient('To',ToName.Text,ToAddress.Text);
      mail.AddHeaderField('Subject',Subject.Text);  // Set the plain-text email body.
      mail.SetPlainTextBody(Body.Text);  // Save the email to an Outlook Express EML file (MIME format)
      mail.WriteFile('mail.eml',mail.ExportToMime());  // Convert the entire email to iso-8859-1 regardless of the character
      // encodings present.
      mail.ConvertToIso8859_1();  // Send the mail.
      if (mail.SendMail() = 0) then
        Status.Caption := 'Send Failed'
      else
        Status.Caption := 'Mail Sent';end;// Delphi example to convert a Western Web page to email and send.
    procedure TForm1.SendWebPageClick(Sender: TObject);
    var
      mail: IMWestern;
    begin
      Status.Caption := 'Sending...';
      Status.Refresh();  mail := CoMWestern.Create();  mail.UnlockComponent('unlockCode');
      mail.SmtpHost := 'smtp.earthlink.net';  // Set email header fields.
      mail.AddHeaderField('From',From.Text);
      mail.AddRecipient('To',ToName.Text,ToAddress.Text);  // Download the Web page into the mail object.  The email subject
      // is initialized to the title of the Web page.
      mail.LoadHtmlComplete(WebUrl.Text);
      

  2.   

    // Replace the subject with something else.
      mail.AddHeaderField('Subject',Subject.Text);  // Save the email to an Outlook Express EML file (MIME format)
      mail.WriteFile('mail2.eml',mail.ExportToMime());  // Convert the entire email to iso-8859-1, regardless of the current
      // encodings.  The entire HTML is also converted, and the HTML meta tag
      // specifing the charset is updated or added.
      mail.ConvertToIso8859_1();  // Send the mail.
      if (mail.SendMail() = 0) then
        Status.Caption := 'Send Failed'
      else
        Status.Caption := 'Mail Sent';end;// Delphi example to convert a Western HTML file to email and send.
    procedure TForm1.SendHtmlCompleteClick(Sender: TObject);
    var
      mail: IMWestern;
    begin
      Status.Caption := 'Sending...';
      Status.Refresh();  // Create an instance of the Western mail object.
      mail := CoMWestern.Create();  // Unlock the component and set the SMTP server.
      mail.UnlockComponent('unlockCode');
      mail.SmtpHost := 'smtp.earthlink.net';  // Set email header fields.
      mail.AddHeaderField('From',From.Text);
      mail.AddRecipient('To',ToName.Text,ToAddress.Text);  // Load the HTML file.  This also loads all images and style sheets
      // and embeds them into the email.
      mail.LoadHtmlComplete(HtmlFile.Text);
      mail.AddHeaderField('Subject',Subject.Text);  // Save the email to an Outlook Express formatted file.
      mail.WriteFile('mail2.eml',mail.ExportToMime());  // Convert the entire email to ISO-8859-1, regardless of existing
      // encodings.
      mail.ConvertToIso8859_1();  // Send the mail.
      if (mail.SendMail() = 0) then
        Status.Caption := 'Send Failed'
      else
        Status.Caption := 'Mail Sent';end;end.