Delphi发送邮件的源码
1个回答
2011-10-26 · 知道合伙人软件行家
关注
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Memo1: TMemo;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with idmessage1 do
begin
body.Clear;
subject:=edit2.text;
From.Text:=edit4.text;
recipients.emailaddresses:=edit3.text;
body.assign(memo1.Lines);
ReceiptRecipient.Text := '';
//if edit7.Text='' then
//tidattachment.Create(idmessage1.MessageParts,edit7.Text);
end;
idsmtp1.authenticationtype:=atnone;
idsmtp1.UserId:=edit5.Text;
idsmtp1.Password:=edit6.Text;
idsmtp1.Host:='smtp.sohu.com';
idsmtp1.Port:=25;
{try
idsmtp1.Connect();
except
application.MessageBox('邮件发送失败!','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;}
try
idsmtp1.Connect;
IdSMTP1.Send(IdMessage1);
application.MessageBox('邮件发送成功!','提示',MB_OK+MB_ICONINFORMATION);
finally
idsmtp1.Disconnect;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Memo1: TMemo;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
with idmessage1 do
begin
body.Clear;
subject:=edit2.text;
From.Text:=edit4.text;
recipients.emailaddresses:=edit3.text;
body.assign(memo1.Lines);
ReceiptRecipient.Text := '';
//if edit7.Text='' then
//tidattachment.Create(idmessage1.MessageParts,edit7.Text);
end;
idsmtp1.authenticationtype:=atnone;
idsmtp1.UserId:=edit5.Text;
idsmtp1.Password:=edit6.Text;
idsmtp1.Host:='smtp.sohu.com';
idsmtp1.Port:=25;
{try
idsmtp1.Connect();
except
application.MessageBox('邮件发送失败!','提示',MB_OK+MB_ICONINFORMATION);
exit;
end;}
try
idsmtp1.Connect;
IdSMTP1.Send(IdMessage1);
application.MessageBox('邮件发送成功!','提示',MB_OK+MB_ICONINFORMATION);
finally
idsmtp1.Disconnect;
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询