Delphi发邮件程序

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase,
  IdSMTP;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Memo1: TMemo;
    IdSMTP1: TIdSMTP;
    IdMessage1: TIdMessage;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if trim(edit1.Text)<>'' then
begin
//建立连接
  idSMTP1.Username:='号码1@qq.com'; //服务器上的用户名
  idSMTP1.Password:='号码1的密码';       //服务器上的密码
  idSMTP1.Host:='smtp.qq.com';          //服务器SMTP地址
  idSMTP1.Port:=25;                     //服务器端口
  try
   idSMTP1.Connect;                      //建立连接
  except
    Showmessage('连接SMTP服务器失败!');
    Exit;
  end;

//发邮件
try
  idMessage1.Body.Clear;
  idMessage1.Body.assign(memo1.Lines);      //邮件正文件内容
  idMessage1.From.Address:=号码1';     //发件人地址
  idMessage1.Recipients.EMailAddresses:=edit1.Text;//收件人地址
  idMessage1.Subject:='Email From Zaitian';        //邮件标题
  idMessage1.Priority:=mpHigh;                     //优先级,mphigh为最高级。
  idSMTP1.Send(idMessage1);
finally
  showmessage('您的信件已成功发送');
  idSMTP1.Disconnect;
end;

end;

end;

end.

有一个遗憾,在D2009下编译运行,如果邮件的主题为汉字的话,那么发出去的邮件的主题将会是乱码,不知道怎么才会不是乱码,可能是D2009的一个BUG吧,如果哪位仁兄知道,请告知,谢谢