H
houxdd
Unregistered / Unconfirmed
GUEST, unregistred user!
本人学写一EMAIL发送程序,但不知为什么只能给自己的邮箱发,不能向smtp服务器以外的
邮箱发,请大家帮助调试一下:
unit umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, VVMSB, StdCtrls, ExtCtrls, IdMessage, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP,
XPMenu, abfComponents, IdAntiFreezeBase, IdAntiFreeze;
type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Memo1: TMemo;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
sb: TVVMStatusBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
idsmtp1: TIdSMTP;
msg: TIdMessage;
OpenDialog1: TOpenDialog;
Edit4: TEdit;
Label4: TLabel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
ComboBox1: TComboBox;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure clearmsg;
procedure sendmail;
procedure Button2Click(Sender: TObject); //清空邮件内容
// procedure IdSMTP1Connected(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.clearmsg;
begin
listbox1.Clear;
memo1.Clear;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
button1.Enabled:=true;
button2.Enabled:=false;
button1.Enabled:=true;
button4.Enabled:=true;
msg.Clear;
sb.Panels[1].Text:='';
end;
procedure TForm1.sendmail;
begin
idsmtp1.Disconnect;
button1.Enabled := false;
button2.Enabled := true;
//---------------------------------------------------连接SMTP服务器
idsmtp1.AuthenticationType:=atNone;
idsmtp1.UserId :='waijw';
idsmtp1.Host:='61.133.126.125';
idsmtp1.Port:=25;
try
sb.Panels[1].Text:='连接服务器......';
sb.Update;
idsmtp1.Connect;
sb.Panels[1].Text:='连接服务器成功!';
sb.Update;
except
showmessage('连接服务器失败!');
end;
//---------------------------------------------------邮件地址、内容等信息
msg.Clear;
msg.Body.Assign(Memo1.Lines);
msg.Recipients.EMailAddresses:=edit1.Text;
msg.From.Address:=edit2.Text;
msg.Subject:=edit3.Text;
msg.CCList.EMailAddresses:=edit4.Text;
// msg.Sender.Address:=edit2.Text;
//-----------------------------------------------------发送邮件
try
sb.Panels[1].Text:='发送邮件......';
sb.Update;
idsmtp1.Send(msg);
sb.Panels[1].Text:='发送邮件成功!';
except
showmessage('发送邮件失败!');
end;
idsmtp1.Disconnect;
clearmsg;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i:integer;
begin
//------------------------------------------------增加邮件附件
if opendialog1.Execute then
for i:=0 to opendialog1.Files.Count-1 do begin
listbox1.Items.Add(opendialog1.Files);
TIdAttachment.Create(msg.MessageParts, opendialog1.Files);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sendmail;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
sb.Panels[1].Text:='取消发送......';
sb.Update;
//idsmtp1.Disconnect;
//clearmsg;
button1.Enabled:=true;
button2.Enabled:=false;
end;
//----------------------------------------------使用线程发送邮件;
end.
邮箱发,请大家帮助调试一下:
unit umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, VVMSB, StdCtrls, ExtCtrls, IdMessage, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP,
XPMenu, abfComponents, IdAntiFreezeBase, IdAntiFreeze;
type
TForm1 = class(TForm)
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Memo1: TMemo;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
sb: TVVMStatusBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
idsmtp1: TIdSMTP;
msg: TIdMessage;
OpenDialog1: TOpenDialog;
Edit4: TEdit;
Label4: TLabel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
ComboBox1: TComboBox;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button4Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure clearmsg;
procedure sendmail;
procedure Button2Click(Sender: TObject); //清空邮件内容
// procedure IdSMTP1Connected(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.clearmsg;
begin
listbox1.Clear;
memo1.Clear;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
button1.Enabled:=true;
button2.Enabled:=false;
button1.Enabled:=true;
button4.Enabled:=true;
msg.Clear;
sb.Panels[1].Text:='';
end;
procedure TForm1.sendmail;
begin
idsmtp1.Disconnect;
button1.Enabled := false;
button2.Enabled := true;
//---------------------------------------------------连接SMTP服务器
idsmtp1.AuthenticationType:=atNone;
idsmtp1.UserId :='waijw';
idsmtp1.Host:='61.133.126.125';
idsmtp1.Port:=25;
try
sb.Panels[1].Text:='连接服务器......';
sb.Update;
idsmtp1.Connect;
sb.Panels[1].Text:='连接服务器成功!';
sb.Update;
except
showmessage('连接服务器失败!');
end;
//---------------------------------------------------邮件地址、内容等信息
msg.Clear;
msg.Body.Assign(Memo1.Lines);
msg.Recipients.EMailAddresses:=edit1.Text;
msg.From.Address:=edit2.Text;
msg.Subject:=edit3.Text;
msg.CCList.EMailAddresses:=edit4.Text;
// msg.Sender.Address:=edit2.Text;
//-----------------------------------------------------发送邮件
try
sb.Panels[1].Text:='发送邮件......';
sb.Update;
idsmtp1.Send(msg);
sb.Panels[1].Text:='发送邮件成功!';
except
showmessage('发送邮件失败!');
end;
idsmtp1.Disconnect;
clearmsg;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i:integer;
begin
//------------------------------------------------增加邮件附件
if opendialog1.Execute then
for i:=0 to opendialog1.Files.Count-1 do begin
listbox1.Items.Add(opendialog1.Files);
TIdAttachment.Create(msg.MessageParts, opendialog1.Files);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sendmail;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
sb.Panels[1].Text:='取消发送......';
sb.Update;
//idsmtp1.Disconnect;
//clearmsg;
button1.Enabled:=true;
button2.Enabled:=false;
end;
//----------------------------------------------使用线程发送邮件;
end.