delphi 邮件发送程序
程序resunitUnit2;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Contr...
程序 res
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, StdCtrls, IdMessage;
type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
SMTP1: TIdSMTP;
IdMessage1: TIdMessage;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
try
SMTP1.AuthenticationType := atLogin;
SMTP1.Username := 'kappernode@sina.cn';
SMTP1.Password := '********';
SMTP1.Host := 'smtp.sina.com.cn';
SMTP1.Port := 25;
SMTP1.Connect();
if SMTP1.Connected then
showmessage('连接服务器成功')
except
showmessage('连接服务器失败');
exit;
end;
IdMessage1.Body.Clear;
IdMessage1.Subject := Edit2.Text;
IdMessage1.Body.Assign(Memo1.Lines);
IdMessage1.From.Address := 'kappernode@sina.cn';
IdMessage1.Recipients.EMailAddresses := edit1.Text;
try
SMTP1.Send(IdMessage1);
showmessage('消息发送成功');
SMTP1.Disconnect;
except
showmessage('消息发送失败');
end;
end;
end.
发送邮件提示成功 但是在邮箱看不到发的邮件 蛋疼了....求大虾解释 是不是被邮件服务器过滤了?怎样才能看到发送的邮件? 展开
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, StdCtrls, IdMessage;
type
TForm2 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
SMTP1: TIdSMTP;
IdMessage1: TIdMessage;
Memo1: TMemo;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
try
SMTP1.AuthenticationType := atLogin;
SMTP1.Username := 'kappernode@sina.cn';
SMTP1.Password := '********';
SMTP1.Host := 'smtp.sina.com.cn';
SMTP1.Port := 25;
SMTP1.Connect();
if SMTP1.Connected then
showmessage('连接服务器成功')
except
showmessage('连接服务器失败');
exit;
end;
IdMessage1.Body.Clear;
IdMessage1.Subject := Edit2.Text;
IdMessage1.Body.Assign(Memo1.Lines);
IdMessage1.From.Address := 'kappernode@sina.cn';
IdMessage1.Recipients.EMailAddresses := edit1.Text;
try
SMTP1.Send(IdMessage1);
showmessage('消息发送成功');
SMTP1.Disconnect;
except
showmessage('消息发送失败');
end;
end;
end.
发送邮件提示成功 但是在邮箱看不到发的邮件 蛋疼了....求大虾解释 是不是被邮件服务器过滤了?怎样才能看到发送的邮件? 展开
2个回答
展开全部
try
// IdSMTP1.AuthenticationType:=atLogin; //设置登陆类型 delphi2006不需要用
IdSMTP1.Username:=''; //设置登陆帐号
IdSMTP1.Password:=''; //设置登陆密码
IdSMTP1.Host:=''; //设置SMTP地址
filename := 'C:\文件.txt'; //需要添加的附件文件
TIdAttachmentfile.Create(IdMessage1.MessageParts,filename); //添加附件
// IdSMTP1.Port:=8080; //设置端口 必须转化为整型 delphi2006不需要用
if not idsmtp1.Connected then
IdSMTP1.Connect; //开始连接服务器
except
Showmessage('连接失败,请重试!');
Exit; //连接失败 的话 退出该执行过程
end;
IdMessage1.Body.Clear; //先清空上次发送的内容
IdMessage1.Subject:='测试'; //设置邮件发送的标题
IdMessage1.Body.add('第一个自动发送邮件测试'); //设置邮件发送的主体
IdMessage1.From.Address:=''; //设置邮件的发件人 也就是说该邮件来自什么地方
//IdMessage1.Recipients.EMailAddresses:=''; //收件人的地址
IdMessage1.CCList.EMailAddresses:='';//抄送
IdMessage1.BccList.EmailAddresses:=''; //密送
IdMessage1.Priority:=mpHighest; //邮件重要性
try
idSMTP1.Send(IdMessage1);
Showmessage('邮件发送成功!');
except
Showmessage('邮件发送失败!');
end;
希望对你有帮助
// IdSMTP1.AuthenticationType:=atLogin; //设置登陆类型 delphi2006不需要用
IdSMTP1.Username:=''; //设置登陆帐号
IdSMTP1.Password:=''; //设置登陆密码
IdSMTP1.Host:=''; //设置SMTP地址
filename := 'C:\文件.txt'; //需要添加的附件文件
TIdAttachmentfile.Create(IdMessage1.MessageParts,filename); //添加附件
// IdSMTP1.Port:=8080; //设置端口 必须转化为整型 delphi2006不需要用
if not idsmtp1.Connected then
IdSMTP1.Connect; //开始连接服务器
except
Showmessage('连接失败,请重试!');
Exit; //连接失败 的话 退出该执行过程
end;
IdMessage1.Body.Clear; //先清空上次发送的内容
IdMessage1.Subject:='测试'; //设置邮件发送的标题
IdMessage1.Body.add('第一个自动发送邮件测试'); //设置邮件发送的主体
IdMessage1.From.Address:=''; //设置邮件的发件人 也就是说该邮件来自什么地方
//IdMessage1.Recipients.EMailAddresses:=''; //收件人的地址
IdMessage1.CCList.EMailAddresses:='';//抄送
IdMessage1.BccList.EmailAddresses:=''; //密送
IdMessage1.Priority:=mpHighest; //邮件重要性
try
idSMTP1.Send(IdMessage1);
Showmessage('邮件发送成功!');
except
Showmessage('邮件发送失败!');
end;
希望对你有帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询