Delphi中如何向Foxmail或者OutLook发送标题、正文信息,启动邮件程序?(0分)

  • 主题发起人 主题发起人 cnhotel
  • 开始时间 开始时间
C

cnhotel

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,可否在程序中中启动foxmail或者outlook,然后向Foxmail或者Outlook发送指定的邮件标题、正文、附件...

咨询...
 
是因为没有分而没有大虾们帮助看看么?
有点提示也行啊
呵呵
祝各位5.1长假愉快
 
虽然没有分
请哪位大哥随便回下我把帖子结了~~省得挂这
 
如果不需要附件,可以试用如下语句:
注意uses shellapi单元
shellexecute(handle,'open',pchar('mailto:ufo2003@126.com?subject=订单&body=订单内容'),nil,nil,sw_shownormal);

如果要添加附件,对于foxmail可以这样:
ss=foxmail可执行文件路径
ss2=附件路径
shellexecute(handle,'open',pchar(ss),pchar(' "'+ss2+'"'),nil,sw_shownormal);

给outlook添加附件,好像比较复杂,现给个例子:
本例中的参数为附件的完整路径,只支持一个附件,如需发多个附件,请自行修改
procedure TForm1.M_sendmail_byoutlook(M_filename: string);
TYPE
TAttachAccessArray = ARRAY [0..0] OF TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
VAR
MapiMessage : TMapiMessage;
Receip : TMapiRecipDesc;
Attachments : PAttachAccessArray;
AttachCount : INTEGER;
iCount : INTEGER;
FileName : STRING;
Mail : TStringlist;
BEGIN
Mail:= Tstringlist.Create;
mail.values['to'] := '';
mail.values['subject'] := '';
mail.values['body'] := '';
mail.values['attachment0'] := M_filename;//附件路径要存在

fillChar(MapiMessage, SizeOf(MapiMessage), #0);
//Attachments := NIL;
fillChar(Receip,SizeOf(Receip), #0);
IF Mail.Values['to'] <> ''
THEN
BEGIN
Receip.ulReserved := 0;
Receip.ulRecipClass := MAPI_TO;
Receip.lpszName := StrNew(PChar(Mail.Values['to']));
Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
Receip.ulEIDSize := 0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @Receip;
END;
AttachCount := 0;
FOR iCount := 0 TO MaxInt
DO
BEGIN
IF Mail.Values['attachment' + IntToStr(iCount)] = ''
THEN
BREAK;
AttachCount := AttachCount + 1;
END;
IF AttachCount > 0
THEN
BEGIN
GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);
FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
FileName := Mail.Values['attachment' + IntToStr(iCount)];
Attachments[iCount].ulReserved := 0;
Attachments[iCount].flFlags := 0;
Attachments[iCount].nPosition := ULONG($FFFFFFFF);
Attachments[iCount].lpszPathName := StrNew(PChar(FileName));
Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
Attachments[iCount].lpFileType := NIL;
END;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
END;

IF Mail.Values['subject'] <> ''
THEN
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
IF Mail.Values['body'] <> ''
THEN
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

//MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);
MapiSendMail(0, Application.Handle, MapiMessage,
MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
(* FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
strDispose(Attachments[iCount].lpszPathName);
strDispose(Attachments[iCount].lpszFileName);
END;

IF assigned(MapiMessage.lpszSubject)
THEN
strDispose(MapiMessage.lpszSubject);
IF assigned(MapiMessage.lpszNoteText)
THEN
strDispose(MapiMessage.lpszNoteText);
IF assigned(Receip.lpszAddress)
THEN
strDispose(Receip.lpszAddress);
IF assigned(Receip.lpszName)
THEN
strDispose(Receip.lpszName); *)

//MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);
mail.Free;
end;
 
谢谢ufo!大哥的回答,本意其实是开贴讨论的,呵呵,估计因为没有分,所以也没有人参与,很感谢你的帮助,我仔细看看代码,先把这个帖子结了~~~省得挂在我的待答问题里面~~~可行的话另开贴转分~~
 
代码是经过测试好用的,另行开贴转分就不必了.
因为我也从这个论坛上得到了不少前辈们的帮助.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部