B
blackant
Unregistered / Unconfirmed
GUEST, unregistred user!
事情的原因是这样的
公司有个同事用delphi4开发了一个程序其中有段用smtp发送email,可是客户用的是lotus notes接收邮件的,所以中文会出现乱码,更要命的是客户那儿的Notes版本较旧,不支持编码转换,而delphi4的tnmsmtp本身又不能指定编码方式,所以我用delphi6做了一个很简单的smtp.dll,全文如下
library Smtp;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
NMSMTp,
Classes;
{$R *.res}
function D6Smtp(MailHostChar;MailPort:Integer;MailFrom,MailTo,MailSubject,MailMessagechar)char;stdcall;
var NMSmtp:TNmSmtp;
begin
//
Try
//1.建立smtp实例
NMSMTP:=TNMSmtp.Create(nil);
//2.连接到smtp服务器,无身份验证
NMSMTP.Host :=MailHost;
NMSMTP.Port :=MailPort;
NMSMTP.Connect();
//3.建立信件内容,仅四项from to subject,body
NMSMTP.PostMessage.FromAddress:=MailFrom;
NMSMTP.PostMessage.ToAddress.Add(MailTo);
NMSMTP.PostMessage.Subject :=MailSubJect;
NMSMTP.PostMessage.Body.Add(MailMessage);
//4.指定charset字符集
NMSMTP.Charset :='GB2312';
//5.发送并关闭连接
NMSMTP.SendMail();
NMSMTP.Disconnect();
//6.释放NMSMTP
NMSMTP.Free;
Result:='Mail发送成功';
Except
On Excep:Exception do
Result:=PChar(Excep.message);
End;
end;
exports
D6Smtp;
begin
end.
然后我尝试在delphi4中调用
procedure TForm1.Button1Click(Sender: TObject);
var
SMTPHandle:THandle;
D6Smtp:TD6Smtp;
MailHost:string;
MailPort:Integer;
MailFrom,MailTo,MailSubject,MailBody:String;
MailResult:String;
begin
try
SMTPHandle :=LoadLibrary('SMTP.Dll');
@D6Smtp:=GetProcAddress(SMTPHandle,'D6Smtp');
MailHost:=self.edit_Host.Text;
MailPort:=StrToInt(Self.Edit_Port.Text);
MailFrom:=Self.Edit_From.Text;
MailTo:=self.Edit_To.Text;
MailSubject:=Self.Edit_Subject.Text;
MailBody:=Self.Edit_Body.text;
MailResult:=D6Smtp(Pchar(MailHost),MailPort,Pchar(MailFrom)
,Pchar(MailTO),Pchar(MailSubject),Pchar(MailBody));
FreeLibrary(SMTPHandle);
Except
On excep:Exception do
ShowMessage(Excep.Message);
End;
end;
以上程序全部通过测试,我认为没有问题了,所以就给同事了,然后故事才发生了
刚才他打电话告诉我,说在客户那儿使用会导致程序崩溃,客户那儿用的是win98
我找了台win98的机器试试好象也正确,并没有提示作任何错误,所以我现在的问题是哪儿可能错了?应该如何修正?乔某在此先得谢过了
公司有个同事用delphi4开发了一个程序其中有段用smtp发送email,可是客户用的是lotus notes接收邮件的,所以中文会出现乱码,更要命的是客户那儿的Notes版本较旧,不支持编码转换,而delphi4的tnmsmtp本身又不能指定编码方式,所以我用delphi6做了一个很简单的smtp.dll,全文如下
library Smtp;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
NMSMTp,
Classes;
{$R *.res}
function D6Smtp(MailHostChar;MailPort:Integer;MailFrom,MailTo,MailSubject,MailMessagechar)char;stdcall;
var NMSmtp:TNmSmtp;
begin
//
Try
//1.建立smtp实例
NMSMTP:=TNMSmtp.Create(nil);
//2.连接到smtp服务器,无身份验证
NMSMTP.Host :=MailHost;
NMSMTP.Port :=MailPort;
NMSMTP.Connect();
//3.建立信件内容,仅四项from to subject,body
NMSMTP.PostMessage.FromAddress:=MailFrom;
NMSMTP.PostMessage.ToAddress.Add(MailTo);
NMSMTP.PostMessage.Subject :=MailSubJect;
NMSMTP.PostMessage.Body.Add(MailMessage);
//4.指定charset字符集
NMSMTP.Charset :='GB2312';
//5.发送并关闭连接
NMSMTP.SendMail();
NMSMTP.Disconnect();
//6.释放NMSMTP
NMSMTP.Free;
Result:='Mail发送成功';
Except
On Excep:Exception do
Result:=PChar(Excep.message);
End;
end;
exports
D6Smtp;
begin
end.
然后我尝试在delphi4中调用
procedure TForm1.Button1Click(Sender: TObject);
var
SMTPHandle:THandle;
D6Smtp:TD6Smtp;
MailHost:string;
MailPort:Integer;
MailFrom,MailTo,MailSubject,MailBody:String;
MailResult:String;
begin
try
SMTPHandle :=LoadLibrary('SMTP.Dll');
@D6Smtp:=GetProcAddress(SMTPHandle,'D6Smtp');
MailHost:=self.edit_Host.Text;
MailPort:=StrToInt(Self.Edit_Port.Text);
MailFrom:=Self.Edit_From.Text;
MailTo:=self.Edit_To.Text;
MailSubject:=Self.Edit_Subject.Text;
MailBody:=Self.Edit_Body.text;
MailResult:=D6Smtp(Pchar(MailHost),MailPort,Pchar(MailFrom)
,Pchar(MailTO),Pchar(MailSubject),Pchar(MailBody));
FreeLibrary(SMTPHandle);
Except
On excep:Exception do
ShowMessage(Excep.Message);
End;
end;
以上程序全部通过测试,我认为没有问题了,所以就给同事了,然后故事才发生了
刚才他打电话告诉我,说在客户那儿使用会导致程序崩溃,客户那儿用的是win98
我找了台win98的机器试试好象也正确,并没有提示作任何错误,所以我现在的问题是哪儿可能错了?应该如何修正?乔某在此先得谢过了