怎么自动发送email?(200分)

  • 主题发起人 主题发起人 book523
  • 开始时间 开始时间
B

book523

Unregistered / Unconfirmed
GUEST, unregistred user!
例如我要从book@163.com向book@sina.com发一封邮件,只需发送简单的文本
(subject=‘粉沙’,内容=‘发达式’)
应该怎么编程?
我想用TIdSmtp,TIdMessage来发送,可是没实现,
IdSmtp.host,Userid,Possword怎么设置?为什么我老是连接不上?
TIdMessage要设置那些属性,才能正确发送上面那封邮件?
假如不用这两个控件,用别的控件要怎么做?
 
怎么自动发送没说啊,我这里有段发邮件的完整代码

procedure Tmail.FormCreate(Sender: TObject);
begin
statusbar1.Panels.Add;

end;
procedure Tmail.ListBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_INSERT then
if OpenDialog1.Execute then
ListBox1.Items.Add(OpenDialog1.FileName);
if Key = VK_DELETE then
ListBox1.Items.Delete(ListBox1.ItemIndex);
end;
procedure Tmail.NMSMTP1AuthenticationFailed(var Handled: Boolean);
var
S: String;
begin
S := NMSMTP1.UserID;
if InputQuery('Authentication Failed', 'Invalid User ID. New User ID: ', S) then
begin
NMSMTP1.UserID := S;
Handled := TRUE;
end;
end;
procedure Tmail.NMSMTP1Connect(Sender: TObject);
begin
statusbar1.Panels[0].text:='正在连接!';
end;
procedure Tmail.NMSMTP1SendStart(Sender: TObject);
begin
statusbar1.Panels[0].text:='开始发送!';
end;
procedure Tmail.NMSMTP1EncodeStart(Filename: String);
begin
statusbar1.Panels[0].text:='开始解码!';
end;
procedure Tmail.NMSMTP1EncodeEnd(Filename: String);
begin
statusbar1.Panels[0].text:='解码完毕!';
end;
procedure Tmail.NMSMTP1Failure(Sender: TObject);
begin
statusbar1.Panels[0].text:='由于未知原因,邮件发送失败,请检查网络后再重发!';
end;
procedure Tmail.NMSMTP1Success(Sender: TObject);
begin
statusbar1.Panels[0].text:='邮件已成功发送!';
end;
procedure Tmail.NMSMTP1HeaderIncomplete(var handled: Boolean;
hiType: Integer);
var
S: String;
begin
case hiType of
hiFromAddress:
if InputQuery('Missing From Address', 'Enter From Address: ', S) then
begin
NMSMTP1.PostMessage.FromAddress := S;
Handled := TRUE;
end;
hiToAddress:
if InputQuery('Missing To Address', 'Enter To Address: ', S) then
begin
NMSMTP1.PostMessage.ToAddress.Text := S;
Handled := TRUE;
end;
end;
end;
procedure Tmail.NMSMTP1Disconnect(Sender: TObject);
begin
statusbar1.panels[0].text:='连接断开!';
end;
procedure Tmail.NMSMTP1ConnectionFailed(Sender: TObject);
begin
statusbar1.Panels[0].text:='连接失败!';
end;
procedure Tmail.FlatButton1Click(Sender: TObject);
begin
if opendialog1.Execute then
ListBox1.Items.Add(OpenDialog1.FileName);
end;

procedure Tmail.FlatButton2Click(Sender: TObject);
begin
if edit1.text<>'' then
begin
if nmsmtp1.Connected then
nmsmtp1.Disconnect
else
begin
nmsmtp1.Host:= edit1.Text;
nmsmtp1.UserID :=edit2.Text;
try
nmsmtp1.Connect;
statusbar1.panels[0].text:='连接成功!';
except
statusbar1.panels[0].text:='无法连接主机!';
end;
end;
end
else
statusbar1.panels[0].text:='警告:主机不能为空!';
end;

procedure Tmail.FlatButton3Click(Sender: TObject);
begin
if nmsmtp1.Connected then
begin
NMSMTP1.PostMessage.FromAddress := Edit3.Text;
NMSMTP1.PostMessage.ToAddress.Text := edit4.text;
NMSMTP1.PostMessage.Body.Text := Memo1.Text;
NMSMTP1.PostMessage.Attachments.Text := ListBox1.Items.Text;
NMSMTP1.PostMessage.Subject := Edit5.Text;
NMSMTP1.SendMail;
end
else
statusbar1.panels[0].text:='警告:当前没连上任何服务器!';
end;

procedure Tmail.FlatButton4Click(Sender: TObject);
begin
mail.Close;
end;

end.
 
type
TForm1 = class(TForm)
IdMessage1: TIdMessage;
Button1: TButton;
IdSMTP1: TIdSMTP;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
Body:TStringList;
begin
Body:=TStringList.Create;
Body.Add('发达式');
IdMessage1.Body.Assign(Body);
IdMessage1.From.Text := 'me@myserver.com';
IdMessage1.Recipients.EMailAddresses := 'book@163.com';
IdMessage1.Subject := '粉沙';

IdSMTP1.UserID :='mydelphi';
IdSMTP1.Password:='delphi';
//如果smtp没有校验用户,可以不用以上两句

IdSMTP1.Host := 'smtp.myserver.com';
IdSMTP1.Connect;
try
IdSMTP1.Send(IdMessage1);
finally
IdSMTP1.Disconnect;
end;
end;
 
delphi有自帶demo 啊
run 就知道了
 
参见 Borland/Delphi6/Demos/Indy/MailClient
另外在 FastNet 中的DEMO也有
 
:lcl_003写的已经够全的了
 
如果是小的应用用WINSOCK来写,
 
to 张无忌
我用socket写了个数据传输的东西,但是要指定服务端的IP,PP点点通可以不指定,我想模仿
不知如何实现
 
to 张无忌:
用winsock写,现在大部分邮箱发送都要认证
你知道相关的命令码么
有相关的资料麻烦给我一份
cbychen@sina.com
 
完成了,全自动发送,用的idsmtp,idmessage
带认证的
 
没看懂啊
 
嘿嘿!!谢谢各大吓!!
我会了!!!今天我就来自己做一个试试~~呵~~[:D]
 
哪位能实现编程发送、接收邮件,给我一份源码,好吗?真诚感谢!
szcanna@yahoo.com.cn
 
后退
顶部