我在网上查到的一段实现发电子邮件的代码,请大家帮我解释一下里面的用法.

Lazywoman 2003-09-11 03:20:10
procedure TForm1.Button1Click(Sender: TObject);
begin
SendMail('Re: mailing from Delphi',
'Welcome to http://www.scalabium.com'#13#10'Mike Shkolnik',
'c:\autoexec.bat',
'your name', 'your@address.com',
'Mike Shkolnik', 'mshkolnik@scalabium.com');
end;

function TForm1.SendMail(const Subject, Body, FileName, SenderName,
SenderEMail, RecipientName, RecipientEMail: string): Integer;
var
Message: TMapiMessage;
lpSender, lpRecipient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;

SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
FillChar(Message, SizeOf(Message), 0); //将message内容赋予0
with Message do
begin
if (Subject <> '') then
lpszSubject := PChar(Subject);

if (Body <> '') then
lpszNoteText := PChar(Body);

if (SenderEmail <> '') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (SenderName = '') then
lpSender.lpszName := PChar(SenderEMail)
else
lpSender.lpszName := PChar(SenderName);
lpSender.lpszAddress := PChar(SenderEmail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;

if (RecipientEmail <> '') then
begin
lpRecipient.ulRecipClass := MAPI_TO;
if (RecipientName = '') then
lpRecipient.lpszName := PChar(RecipientEMail)
else
lpRecipient.lpszName := PChar(RecipientName);
lpRecipient.lpszAddress := PChar(RecipientEmail);
lpRecipient.ulReserved := 0;
lpRecipient.ulEIDSize := 0;
lpRecipient.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @lpRecipient;
end
else
lpRecips := nil;

if (FileName = '') then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
FillChar(FileAttach, SizeOf(FileAttach), 0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(FileName);

nFileCount := 1;
lpFiles := @FileAttach;
end;
end;

MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule = 0 then
Result := -1
else
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM <> nil then
begin
Result := SM(0, Application.Handle, Message, MAPI_DIALOG or MAPI_LOGON_UI, 0);
end
else
Result := 1;
finally
FreeLibrary(MAPIModule);
end;

if Result <> 0 then
MessageDlg('Error sending mail (' + IntToStr(Result) + ').', mtError,
[mbOK], 0);
end;
我要做的是给默认的电子邮件系统添加上默认的主题,收件人的地址,附件.我用shellexecute函数时不能加上附件,而用上面的方法则可以.所以我用上面的方法,但里面的代码有点看不懂,请大家帮我分析一下.
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lazywoman 2003-09-11
  • 打赏
  • 举报
回复
什么DLL呀,请blueshrimp(下着沙-软件民工)详细点行不,我看它就是调用了MAPI32.DLL中的'MAPISendMail'函数,可是这个运行速度有点慢,我想把它弄成静态调用,可运行时要抱错.还有前面那些数据结构好难懂哟,这些数据结构是定义来专门发送邮件的吗.
blueshrimp 2003-09-11
  • 打赏
  • 举报
回复
这个不用管,需要一个DLL

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧