全不分数啦!!发Email的问题?(20分)

  • 主题发起人 主题发起人 至尊王
  • 开始时间 开始时间

至尊王

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用TidMessage和TidSMTP控件发送邮件(带附件)???在线等待!
 
没人知道??
 
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.
 
我说的是:用TidMessage和TidSMTP控件发送邮件(带附件)
 
delphi安装目录/Demo/Indy/Mailclient
 
真希望有人能够详细得给大家介绍一下IDMessage和IDSMTP.....我出50分!
 
后退
顶部