这是它自带例子的代码:
procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
begin
if AHMAccountHolder1.Accounts.Count=0 then
with AHMAccountHolder1.Accounts.Adddo
begin
AccountName:='Current Account';
SMTPServer:=Edit5.text;
Default:=True;
{Default is the account that will be used for sending messages. At least one account needs to default to send messages}
end else
with AHMAccountHolder1.Accounts[0]do
begin
AccountName:='Current Account';
SMTPServer:=Edit5.text;
end;
with AHMSMTPMail1.Messages.Adddo
try
Subject :=Edit1.Text;
SendTo :=Edit2.text;
Message.Text:=Memo1.Lines.Text;
FromMail :=Edit3.Text;
ReplyTo :=Edit3.Text;
FromName :=edit4.text;
//Having stored the filenames of wanted attachments within a listbox you cando
the following
if Listbox1.Items.Count>0 then
For I:=0 to Listbox1.Items.Count-1do
Attachments.Add(Listbox1.Items);
AHMSMTPMail1.Execute;
finally
Free;
end;
end;
后来我改成这样也不行:
procedure TForm1.Button1Click(Sender: TObject);
var I : Integer;
begin
if AHMAccountHolder1.Accounts.Count=0 then
with AHMAccountHolder1.Accounts.Adddo
begin
AccountName:='Current Account';
SMTPServer:=Edit5.text;
Username:='xxxxxxxx';
Password:='123456';
//SMTPPort:=25;
Default:=True;
{Default is the account that will be used for sending messages. At least one account needs to default to send messages}
end else
with AHMAccountHolder1.Accounts[0]do
begin
AccountName:='Current Account';
SMTPServer:=Edit5.text;
Username:='xxxxxxxx';
Password:='123456';
//SMTPPort:=25;
end;
with AHMSMTPMail1.Messages.Adddo
try
Subject :=Edit1.Text;
SendTo :=Edit2.text;
Message.Text:=Memo1.Lines.Text;
FromMail :=Edit3.Text;
ReplyTo :=Edit3.Text;
FromName :=edit4.text;
//Having stored the filenames of wanted attachments within a listbox you cando
the following
if Listbox1.Items.Count>0 then
For I:=0 to Listbox1.Items.Count-1do
Attachments.Add(Listbox1.Items);
AHMSMTPMail1.Execute;
finally
Free;
end;
end;