 |
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
cityhe4520
註冊時間: 2004-09-15 文章: 28
第 1 樓
|
發表於: 星期五 九月 24, 2004 11:56 pm 文章主題: 請問各位高手 outlook 問題, 請幫忙 , 謝!! |
|
|
oEmail = create("MSMAPI.MAPISession")
oEmail = create("MSMAPI.MAPIMessages")
請問以上的 send email 方法, 如何可以自動傳送呢 ? 不需要有視窗問我傳不傳送呢??
請高手指點, 謝謝 |
|
回頂端 |
|
 |
goto-dream
註冊時間: 2004-05-11 文章: 909
第 2 樓
|
發表於: 星期六 九月 25, 2004 1:34 am 文章主題: |
|
|
給你兩個程式碼
代碼: | #DEFINE cret Chr(13)+Chr(10)
#DEFINE dret cret+cret
PRIVATE obj
obj = CreateObject("MapiSendMail")
WITH obj
* though the Sender object is implemented I never managed to make it
* something else but the default address for the local email client
.AddSender("A.A.", "someone@somwhere.mail")
* add one or more recipients
* note that the following ones will not work, just an example
.AddRecipient("Chivas Regal", "info@chivasregal.mail")
.AddRecipient("Jim Beam", "info@.jimbeam.mail")
.AddRecipient("John Walker", "info@.johnwalkermail")
.AddRecipient("Canadian Club", "info@.canclubmail")
.MsgSubject = "Test Message"
.MsgBody ="This text will be put into body of your message." + dret +;
"You can also use table fields and Text and Edit Boxes." + dret +;
"Source:" + cret +;
"http://www.news2news.com/vfp"
* adding file attachments
* make sure that all files are available
.AddAttachment("C:\myfiles\Resume\cover.txt")
.AddAttachment("C:\myfiles\Resume\cv.doc")
.AddAttachment("C:\myprogs\sample.PRG")
.SndMessage
ENDWITH |
代碼: | DEFINE CLASS MapiSendMail As Custom
#DEFINE SUCCESS_SUCCESS 0
MsgSubject=""
MsgBody=""
snd=.F.
rcp=.F.
att=.F.
PROCEDURE Init
THIS.snd = CreateObject("TRecipients")
THIS.rcp = CreateObject("TRecipients")
THIS.att = CreateObject("TAttachments")
PROCEDURE SndMessage
IF Not THIS.ValidMessage()
RETURN .F.
ENDIF
LOCAL lcMapiMessage, loSubject, loBody, ii, lnResult, lcStoredPath
loSubject = CreateObject("PChar", THIS.MsgSubject)
loBody = CreateObject("PChar", THIS.MsgBody)
lcStoredPath = SYS(5) + SYS(2003)
* assembling MapiMessage structure
lcMapiMessage = num2dword(0) +;
num2dword(loSubject.getAddr()) + num2dword(loBody.getAddr()) +;
num2dword(0) + num2dword(0) + num2dword(0) + num2dword(0) +;
num2dword(THIS.snd.getAddr()) +;
num2dword(THIS.rcp.ItemCount) + num2dword(THIS.rcp.GetAddr()) +;
num2dword(THIS.att.ItemCount) +;
num2dword(Iif(THIS.att.ItemCount=0, 0,THIS.att.GetAddr()))
DECLARE INTEGER MAPISendMail IN mapi32;
INTEGER lhSession, INTEGER ulUIParam, STRING @lpMessage,;
INTEGER flFlags, INTEGER ulReserved
lnResult = MAPISendMail(0, 0, @lcMapiMessage, 8, 0)
SET DEFAULT TO (lcStoredPath)
do case
case lnResult = 1
* 1 MAPI_E_USER_ABORT
case lnResult = 2
* 2 MAPI_E_FAILURE
messagebox("Failure while sending email.")
case lnResult = 3
* 3 MAPI_E_LOGIN_FAILURE
messagebox("Login failure on email account.")
case lnResult = 5
* 5 MAPI_E_INSUFFICIENT_MEMORY
messagebox("Insufficient memory to carry out email operation.")
case lnResult = 6
* 6 MAPI_E_ACCESS_DENIED
messagebox("Access denied while executing email operation.")
case lnResult = 9
* 9 MAPI_E_TOO_MANY_FILES
messagebox("Too many files to carry out email operation.")
case lnResult = 10
*10 MAPI_E_TOO_MANY_RECIPIENTS
messagebox("Too many recipients to carry out email operation.")
case lnResult = 14
*14 MAPI_E_UNKNOWN_RECIPIENT
messagebox("Unknown recipient(s). Email will not be sent.")
case lnResult = 15
*15 MAPI_E_BAD_RECIPTYPE
messagebox("Bad recipient(s). Email will not be sent.")
case lnResult = 18
*18 MAPI_E_TEXT_TOO_LARGE
messagebox("Text is too large to carry out email operation.")
otherwise
* 0 = Success
endcase
RETURN (lnResult=0) && sendmessage
FUNCTION ValidMessage
LOCAL lValid
lValid = THIS.rcp.ItemCount > 0 And;
Not (EMPTY(THIS.MsgSubject) And EMPTY(THIS.MsgBody);
And THIS.att.ItemCount=0)
IF Not m.lValid
IF THIS.rcp.ItemCount = 0
= MessageB ("The outgoing message is invalid." + Chr(13) +;
"Recipients not defined.", 48, " Invalid message data")
ELSE
= MessageB ("The outgoing message is invalid." + Chr(13) +;
"At least one has to be valid: subj, body, attachments.",;
48, " Invalid message data")
ENDIF
ENDIF
RETURN m.lValid
PROCEDURE ClearMessage
THIS.ClearRecipients
THIS.ClearAttachments
THIS.MsgBody=""
THIS.MsgSubject=""
PROCEDURE AddSender (lcSndName, lcSndAddr)
#DEFINE MAPI_ORIG 0
IF TYPE("lcSndAddr") <> "C"
lcSndAddr = lcSndName
ENDIF
THIS.snd.AppendItem (MAPI_ORIG, lcSndName, lcSndAddr)
PROCEDURE AddRecipient(lcRcpName, lcRcpAddr, To_CC)
* To_CC - 1 = To, 2 = CC
#DEFINE MAPI_TO 1
#DEFINE MAPI_CC 2
IF TYPE("lcRcpAddr") <> "C"
lcRcpAddr = lcRcpName
ENDIF
if type("To_CC") <> 'N'
To_CC = 1
endif
LOCAL
...truncated; exceeds the max length |
_________________ 福隆昌淨水有限公司--淨水器的專家,淨水器,飲水機,濾心!!
想了解更多,您可上幸福雞湯組.找尋!!丁澐瑄.老師.
愛作夢 |
|
回頂端 |
|
 |
goto-dream
註冊時間: 2004-05-11 文章: 909
第 3 樓
|
|
回頂端 |
|
 |
cityhe4520
註冊時間: 2004-09-15 文章: 28
第 4 樓
|
發表於: 星期六 九月 25, 2004 10:48 pm 文章主題: |
|
|
真心多謝你的幫忙!! |
|
回頂端 |
|
 |
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|