下面的程序经过测试是OK的,使用了INDY控件,可以发给WWW邮箱:
unit email_Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, StdCtrls, IdMessage;
type
TForm1 = class(TForm)
IdSMTP1: TIdSMTP;
Button1: TButton;
IdMessage1: TIdMessage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Attachment_name:String;
begin
Attachment_name:='d:/attachment.rar';
IdSMTP1.AuthenticationType:=atLogin;
IdSMTP1.Host:='smtp.sohu.com';
IdSMTP1.Port:=25;
IdSMTP1.Username:='aaa';
IdSMTP1.Password:='bbb';
IdMessage1.Body.add('测试中文4');
IdMessage1.From.Text:='abc@a.com';
IdMessage1.Recipients.EMailAddresses:='aaa@sina.com';
//IdMessage1.CCList.EMailAddresses := edtCC.Text;// {CC}
//IdMessage1.BccList.EMailAddresses:='aaa@b.com' //{BBC}
IdMessage1.Subject:='This is a test !';
if FileExists(Attachment_name) then TIdAttachment.Create(IdMessage1.MessageParts,Attachment_name);
try
IdSMTP1.Connect(-1);
IdSMTP1.Send(IdMessage1);
showmessage('OK');
except
showmessage('Error !');
end;
IdSMTP1.Disconnect;
end;
end.