3个回答
展开全部
你的程序有很多问题.我单看了你调用SendMail这个过程就有问题.
你的SendMail过程在定义是没有定义参数:
procedure SendEmail(Sender: TObject);,
可是在下面却又需要传入参数:
procedure TForm1.SendEmail(Recipient,Address:string); .
我估计你这个SendMail的过程是直接Copy人家的.这样肯定会出问题的.
我根据你的意思写了一个差不多的程序.该程序能够读取到程序目录下一个'rf.txt'文件,并将该文件的内容作为将要发送的邮件内容.
需要在窗体中放置一个TIDMessage控件,一个TIdSMTP控件
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)
SMTP: TIdSMTP;
IdMsgSend: TIdMessage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure sendmail(sbody:TStrings);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Email : Textfile;
Bodytxt : tstrings;
s:string;
begin
Bodytxt := TStringList.Create;
try
AssignFile(Email,extractfilepath(application.ExeName) + 'rf.txt');
reset(Email);
while not EOF(Email) do
begin
readln(Email, s);
Bodytxt.Add(s);
end;
SendMail(Bodytxt);//调用SendMail,传入邮件内容BodyTxt
finally
closefile(email);
end;
ShowMessage('SendMail OK!');
end;
procedure TForm1.sendmail(sBody : TStrings);
begin
with IdMsgSend do
begin
Body := sBody; //邮件内容
From.Text := 'xxxx'; //发件人
Recipients.EMailAddresses := 'xxxx'; { To: header } //收件人
Subject := 'yyyy'; //邮件主旨
tidattachment.Create(IdMsgSend.MessageParts,'D:\Excel\Test.xls');//发送附件,可发送多个
SMTP.Host := 'smtp.michael.com' ; // 主机名称
SMTP.Port := 25; // PORT
SMTP.Connect;
try
try
SMTP.Send(IdMsgSend);
except
end;
finally
SMTP.Disconnect;
end;
end;
end;
end.
还有问题的话,可以发消息给我.
你的SendMail过程在定义是没有定义参数:
procedure SendEmail(Sender: TObject);,
可是在下面却又需要传入参数:
procedure TForm1.SendEmail(Recipient,Address:string); .
我估计你这个SendMail的过程是直接Copy人家的.这样肯定会出问题的.
我根据你的意思写了一个差不多的程序.该程序能够读取到程序目录下一个'rf.txt'文件,并将该文件的内容作为将要发送的邮件内容.
需要在窗体中放置一个TIDMessage控件,一个TIdSMTP控件
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)
SMTP: TIdSMTP;
IdMsgSend: TIdMessage;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure sendmail(sbody:TStrings);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Email : Textfile;
Bodytxt : tstrings;
s:string;
begin
Bodytxt := TStringList.Create;
try
AssignFile(Email,extractfilepath(application.ExeName) + 'rf.txt');
reset(Email);
while not EOF(Email) do
begin
readln(Email, s);
Bodytxt.Add(s);
end;
SendMail(Bodytxt);//调用SendMail,传入邮件内容BodyTxt
finally
closefile(email);
end;
ShowMessage('SendMail OK!');
end;
procedure TForm1.sendmail(sBody : TStrings);
begin
with IdMsgSend do
begin
Body := sBody; //邮件内容
From.Text := 'xxxx'; //发件人
Recipients.EMailAddresses := 'xxxx'; { To: header } //收件人
Subject := 'yyyy'; //邮件主旨
tidattachment.Create(IdMsgSend.MessageParts,'D:\Excel\Test.xls');//发送附件,可发送多个
SMTP.Host := 'smtp.michael.com' ; // 主机名称
SMTP.Port := 25; // PORT
SMTP.Connect;
try
try
SMTP.Send(IdMsgSend);
except
end;
finally
SMTP.Disconnect;
end;
end;
end;
end.
还有问题的话,可以发消息给我.
展开全部
用html格式发送,网页文件html中可以添加背景图片,图片以附件保存contenttype:='image/图片类型';contenttransfer:='base64';extraheaders.values['Content-ID']:='<'+图片CID+'>';
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
关注一下这个问题!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询