为什么这个邮件发送程序不能发送邮件?

csdncdb 2001-08-21 08:08:11
我照着书上打出的,为什么不能发送邮件?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Psock, NMsmtp, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
ToAddress: TEdit;
ToCarbonCopy: TEdit;
Attachment: TEdit;
FromAddress: TEdit;
UserID: TEdit;
Subject: TEdit;
ToBlindCarbonCopy: TEdit;
FromName: TEdit;
Host: TEdit;
SendButton: TButton;
NewButton: TButton;
ClearButton: TButton;
AttachButton: TButton;
CloseButton: TButton;
Body: TMemo;
OpenDialog: TOpenDialog;
NMSMTP: TNMSMTP;
StatusBar: TStatusBar;
procedure SendButtonClick(Sender: TObject);
procedure NewButtonClick(Sender: TObject);
procedure ClearButtonClick(Sender: TObject);
procedure AttachButtonClick(Sender: TObject);
procedure CloseButtonClick(Sender: TObject);
procedure NMSMTPAuthenticationFailed(var Handled: Boolean);
procedure NMSMTPSuccess(Sender: TObject);
procedure NMSMTPFailure(Sender: TObject);
procedure NMSMTPHeaderIncomplete(var handled: Boolean;
hiType: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SendButtonClick(Sender: TObject);
begin
Form1.Cursor :=crHourGlass;
SendButton.Enabled :=False;
newbutton.Enabled :=false;
clearbutton.Enabled :=false;
attachbutton.Enabled :=false;
statusbar.SimpleText :='正在连接服务器,请稍候...';
nmsmtp.PostMessage.toaddress.Text :=toaddress.text;
nmsmtp.PostMessage.Subject :=subject.text;
nmsmtp.PostMessage.tocarboncopy.text :=tocarboncopy.text;
nmsmtp.PostMessage.ToblindCarbonCopy.Text :=toblindcarboncopy.text;
nmsmtp.PostMessage.FromAddress :=fromaddress.text;
nmsmtp.PostMessage.FromName :=fromname.text;
nmsmtp.PostMessage.attachments.text :=attachment.text;
nmsmtp.PostMessage.Body.text :=body.text;
nmsmtp.PostMessage.Date :=datetimetostr(now);
nmsmtp.PostMessage.ReplyTo :=fromaddress.text;
nmsmtp.Host :=host.Text;
nmsmtp.UserID :=userid.text;
nmsmtp.Connect;
nmsmtp.SendMail;
nmsmtp.Disconnect;
end;

procedure TForm1.NewButtonClick(Sender: TObject);
begin
toaddress.Clear;
subject.Clear;
tocarboncopy.Clear;
toblindcarboncopy.Clear;
attachment.Clear;
body.Clear;
end;

procedure TForm1.ClearButtonClick(Sender: TObject);
begin
nmsmtp.ClearParameters;
toaddress.Clear;
subject.clear;
tocarboncopy.Clear;
toblindcarboncopy.Clear;
attachment.clear;
body.Clear;
fromaddress.clear;
fromname.clear;
host.Clear;
userid.clear;
end;

procedure TForm1.AttachButtonClick(Sender: TObject);
begin
if opendialog.Execute then attachment.text :=(opendialog.FileName);

end;

procedure TForm1.CloseButtonClick(Sender: TObject);
begin
close;
end;

procedure TForm1.NMSMTPAuthenticationFailed(var Handled: Boolean);
var
S:string;

begin
s:=nmsmtp.UserID;
if inputquery('身份验证失败','请重新输入用户名(UserID)',S) then
begin
nmsmtp.UserID :=S;
handled :=true;
end; //question
end;

procedure TForm1.NMSMTPSuccess(Sender: TObject);
begin
messagedlg('邮件已经成功发送',mtinformation, [mbyes],0);
sendbutton.enabled :=true;
newbutton.Enabled :=true;
clearbutton.enabled :=true;
attachbutton.enabled :=true;
form1.Cursor :=crdefault;
statusbar.SimpleText :='已经成功发送邮件';
end;

procedure TForm1.NMSMTPFailure(Sender: TObject);
begin
messagedlg('邮件发送失败',mtinformation,[mbyes],0);
sendbutton.enabled :=true;
newbutton.Enabled :=true;
clearbutton.enabled :=true;
attachbutton.enabled :=true;
form1.Cursor :=crdefault;
statusbar.simpletext :='发送邮件失败';
end;

procedure TForm1.NMSMTPHeaderIncomplete(var handled: Boolean;
hiType: Integer);
var
Str:STRING;
begin
case hiType of
hiFromAddress:
if inputQuery('发件人地址没有填写','请输入发件人地址:',Str) then
begin
nmsmtp.PostMessage.FromAddress :=Str;
handled :=true;
end;
hitoAddress:
if inputquery('收件人地址没有填写','请输入收件人地址:',Str) then
begin
nmsmtp.PostMessage.ToAddress.Text :=str;
handled :=true;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.
...全文
55 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
devecom 2001-08-21
  • 打赏
  • 举报
回复
应该是SMTP验证的问题
nne998 2001-08-21
  • 打赏
  • 举报
回复
有的 smtp服务器是需要身份认证的!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧