如何開啟預設的收發信件軟體,並填入附加檔案?? |
|
cjm888
一般會員 發表:3 回覆:3 積分:1 註冊:2002-04-05 發送簡訊給我 |
|
lee
站長 發表:55 回覆:173 積分:45 註冊:2002-02-27 發送簡訊給我 |
引言: 請問一下!! 我想要在程式上,讓使用者可以選擇檔案並寄出email 我要如何開啟預設的收發信件軟體(如Outlook Express) 並將收件者,附加檔案的值填入其內. ShellExecute( Application.Handle, 'open', PChar('mailto:aaa@bb.cc.dd'), nil, nil, SW_ShowNormal ); 好像只有填入email,如果要填入附加檔案的話,不知道應該怎麼做?? 謝謝!!為何不用Delphi內附的發信元件發信呢?也可附加檔案發信! 若用內定的發信軟體,發信軟體種類很多,像我是用Beck-Mail! 若是用OutLook發信,可能要採用Comobj的方式,用shellexecute應是達不到! ~~~Delphi K.Top網站總管~~~
------
~~~Delphi K.Top網站總管~~~ |
領航天使
站長 發表:12216 回覆:4186 積分:4084 註冊:2001-07-25 發送簡訊給我 |
引言: ShellExecute( Application.Handle, 'open', PChar('mailto:aaa@bb.cc.dd'), nil, nil, SW_ShowNormal ); 好像只有填入email,如果要填入附加檔案的話,不知道應該怎麼做??填入主題與內文可以用: ShellExecute(0,nil,'mailto:TEST@TEST.TEST?Subject=這是主題&body=這是內文',nil,nil,sw_showdefault); 再試過: ShellExecute(0,nil,'mailto:TEST@TEST.TEST?Subject=這是主題&body=這是內文&attach=c:\test.txt',nil,nil,sw_showdefault); 卻無法成功,網路上有一篇英文的討論信: Q:Can anybody show me how to use ShellExecute to prepare a e-mail with an attachment or how to use 'Send to' function from Windows context menu programatically. (有人可告訴我如何用ShellExecute送出一封含附檔的郵件?) A1:You can not attach files using the mailto, which is what you would have to do to use shellexecute. The only way I know of is to use OLE or scripting. (您不可用Mailto來附加檔案,我想可能要用OLE或Script) A2:instead of using VBS you can import the Outlook Typelibrary (OLE). D4 has not the server components like D5. The sample code is from a D4 project. (不用VBS可在D4用OLE寫如下程式) {outlook_tlb.pas is in your imports directory after you imported the outlook typelibrary} procedure TForm1.SendMailViaOutlook; var Unkown : IUnkown; Result : IUnkown; FOutLook : _Application; OutlookIsRunning : Boolean; MI : _MailItem; FAttachmentFilename : String; begin // Start Outlook -> {If an Outlook instance is running then use this instance} OutlookWasRunning:=False; Result := GetActiveObject(CLASS_Application_, nil, Unknown); if (Result = MK_E_UNAVAILABLE) then begin Try FOutlook := CoApplication_.Create Except MessageDLG('This App works only with Outlook',mtError,[mbOk],0); Exit; end; end else begin { make sure no other error occurred during GetActiveObject } OleCheck(Result); OleCheck(Unknown.QueryInterface(_Application, FOutlook)); OutlookWasRunning:=True; end; // <- Start Outlook Try FAttachmentFilename:='c:\something'; MI:= FOutlook.CreateItem(olMailItem) as _MailItem; Application.ProcessMessages; MI.HTMLBody :='Your messages Text; MI.Attachments.Add(FAttachmentFilenam,EmptyParam,EmptyParam, 'Title below the attachmnet icon'); MI.Display(1); // 1 show Outlook modal Finally If Not OutlookWasRunning then FOutlook.Quit; FOutlook:=Nil; end; end;以上供您參考! ~~~Delphi K.Top討論區站長~~~
------
~~~Delphi K.Top討論區站長~~~ |
mnsf
初階會員 發表:104 回覆:90 積分:48 註冊:2003-11-25 發送簡訊給我 |
引言: [quote] ShellExecute( Application.Handle, 'open', PChar('mailto:aaa@bb.cc.dd'), nil, nil, SW_ShowNormal ); 好像只有填入email,如果要填入附加檔案的話,不知道應該怎麼做??填入主題與內文可以用: ShellExecute(0,nil,'mailto:TEST@TEST.TEST?Subject=這是主題&body=這是內文',nil,nil,sw_showdefault); 再試過: ShellExecute(0,nil,'mailto:TEST@TEST.TEST?Subject=這是主題&body=這是內文&attach=c:\test.txt',nil,nil,sw_showdefault); 卻無法成功,網路上有一篇英文的討論信: Q:Can anybody show me how to use ShellExecute to prepare a e-mail with an attachment or how to use 'Send to' function from Windows context menu programatically. (有人可告訴我如何用ShellExecute送出一封含附檔的郵件?) A1:You can not attach files using the mailto, which is what you would have to do to use shellexecute. The only way I know of is to use OLE or scripting. (您不可用Mailto來附加檔案,我想可能要用OLE或Script) A2:instead of using VBS you can import the Outlook Typelibrary (OLE). D4 has not the server components like D5. The sample code is from a D4 project. (不用VBS可在D4用OLE寫如下程式) {outlook_tlb.pas is in your imports directory after you imported the outlook typelibrary} procedure TForm1.SendMailViaOutlook; var Unkown : IUnkown; Result : IUnkown; FOutLook : _Application; OutlookIsRunning : Boolean; MI : _MailItem; FAttachmentFilename : String; begin // Start Outlook -> {If an Outlook instance is running then use this instance} OutlookWasRunning:=False; Result := GetActiveObject(CLASS_Application_, nil, Unknown); if (Result = MK_E_UNAVAILABLE) then begin Try FOutlook := CoApplication_.Create Except MessageDLG('This App works only with Outlook',mtError,[mbOk],0); Exit; end; end else begin { make sure no other error occurred during GetActiveObject } OleCheck(Result); OleCheck(Unknown.QueryInterface(_Application, FOutlook)); OutlookWasRunning:=True; end; // <- Start Outlook Try FAttachmentFilename:='c:\something'; MI:= FOutlook.CreateItem(olMailItem) as _MailItem; Application.ProcessMessages; MI.HTMLBody :='Your messages Text; MI.Attachments.Add(FAttachmentFilenam,EmptyParam,EmptyParam, 'Title below the attachmnet icon'); MI.Display(1); // 1 show Outlook modal Finally If Not OutlookWasRunning then FOutlook.Quit; FOutlook:=Nil; end; end; [/code] 以上供您參考! ~~~Delphi K.Top討論區站長~~~ 站長你好,我將上面那段程式碼compiler以後會有一些錯誤訊息 [Error] Unit1.pas(27): Undeclared identifier: 'IUnkown' [Error] Unit1.pas(29): Undeclared identifier: '_Application' [Error] Unit1.pas(31): Undeclared identifier: '_MailItem' [Error] Unit1.pas(36): Undeclared identifier: 'OutlookWasRunning' [Error] Unit1.pas(37): Undeclared identifier: 'GetActiveObject' [Error] Unit1.pas(37): Undeclared identifier: 'CLASS_Application_' 等等 請問是不是要uses 些什麼東西,才可以compiler成功呢? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |