在线等待,急!急急!!(50分)

  • 主题发起人 主题发起人 leo_zzz
  • 开始时间 开始时间
L

leo_zzz

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能给一个完整的例子,演示发送email

不调用outlook 等软件,

如 用 从sender@sina.com 发信到 reciever@163.com

信题目:“title”

内容:content1
content2
content3
content4

sina 的smtp是:smtp.sina.com.cn

而且sina 的smtp的服务器需要 身份验证

--------------
高手请给个例子吧

 
据说要用 Tidsmtp 怎么用啊? 谁能教教我?
 
让俺想一想,不会很久的[:D]
 
var
mail: Tmail;

implementation

uses MainForm;

{$R *.DFM}

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.
 
有个sakemail,我用过一次,感觉不错
www.playicq.com有下载
 
lcl_003大哥,smtp的身份验证怎么解决阿,有人说用idsmtp控件,可是我不会用啊,
大家谁会啊??
 
我的程序好象有身份验证啊,我记得用它我还发现163的smtp的一个bug呢。
 
不好意思,我没看懂,你程序中password在哪里输入?
 
哦,我想起来了,我的程序里没有进行身份验证,当时是因为没有身份验证所以才发现
了用我的程序可以饶过163的smtp验证,呵呵,不好意思。
找了段有身份验证的。另外Borland/Delphi6/Demos/Indy/MailClient有例子啊,带身份
验证。


procedure Tform1.SendAlarmEmail;
begin
if SMTPAuthority then //SMTPAuthority 是 表示这个SMTP服务器是否需要认证的boolean
SMTP.AuthenticationType := atLogin
else SMTP.AuthenticationType := atNone;
SMTP.UserID := myzerg@263.net;//帐户
SMTP.Password := **********;//密码
{General setup}
SMTP.Host := SMTP.263.net;
SMTP.Port := 25;
try
SMTP.Connect;
except
Showmessage('连接SMTP服务器失败!');
Exit;
end;
try
with IdMsgSend do
begin
body.Clear;
Body.Add('hello world');//内容
From.Text := 'myzerg@263.net';
Recipients.EMailAddresses :='zyx_chz@263.net'//收件人
Subject:='老友,哈喽'//主题
end;
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
end;
 
好象是沒有驗證密碼的代碼!?
我也碰到這個問題!
 
ok,谢谢lcl_03,谢谢delphi的例子,我终于明白了

给分
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部