VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

請問VFP如何用SMTP發mail

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
jackyai



註冊時間: 2005-07-28
文章: 3


第 1 樓

發表發表於: 星期四 七月 28, 2005 4:21 pm    文章主題: 請問VFP如何用SMTP發mail 引言回覆

我曾在VFP使用Session和Mapi的物件發送Mail,但限定在Outlook的環境,請問用什麼方法可以在Notes 的環境發Mail,不知各位
先進是否有人知其作法,請不吝指教?


感謝各位先進給我的方法,昨天終於有機會測試,不過可能是我使用的方法有問題吧,如果會發生如下的錯誤訊息
OLE錯誤程式碼0x80020006: Unknown Name

以下是本寫的程式碼,如果有那位知道的請告訴我,謝謝!!

LPARAMETERS laSendTo, laCC, laBcc, lcSubject, lcBody

laSendTo:收件者
laCC:副本
laBcc:密件副本
lcSubject:主旨
lcBody:本文

LOCAL loSession && the note session to be oppened
LOCAL lcServer && notes server
LOCAL lcMaildbName && Mail db Name
LOCAL loMaildb && Mail db object
LOCAL loMailDoc && Document object, the email itself
LOCAL loStream && text stream used to attach a MIME document to the email object
&& i.e the Body of the object.
loSession = CREATEOBJECT( "Lotus.NotesSession" )
loSession.Initialize( )

lcServer = loSession.GetEnvironmentString( "MailServer",.t.)
lcMaildbName = loSession.GetEnvironmentString( "MailFile",.t.)
loMaildb = loSession.getdatabase(lcServer, lcMaildbName )

loMaildoc = loMaildb.CreateDocument()
* Who do we send it to
loMaildoc.ReplaceItemValue( "Form", "Memo" )
IF !EMPTY( laSendTo )
loMaildoc.ReplaceItemValue( "SendTo", @laSendTo )
ENDIF
IF !EMPTY( laCC )
loMaildoc.ReplaceItemValue( "CopyTo", @laCC )
ENDIF
IF !EMPTY( laBcc )
loMaildoc.ReplaceItemValue( "BlindCopyTo", @laBcc)
ENDIF

* The subject
loMaildoc.replaceitemValue( "Subject", lcSubject )

* The Body
loStream = loSession.CreateStream()
loStream.WriteText( lcBody )
* The Body MIME type
loBodyMime = loMailDoc.CreateMIMEEntity()
loBodyMime.SetContentFromText( loStream, "text/html;charset=iso-8859-1", .f. )

* this bit just me playing with the paper type and icons displaid in Notes.
* If its a propery in Notes then you can change it like this....
*(i.e. right click on the message, Document Proterties, 2nd tab...then experiment)
loMaildoc.ReplaceItemValue( "Logo", "StdNotesLtr3" )
loMaildoc.ReplaceItemValue( "_ViewIcon", 23 )
loMaildoc.ReplaceItemValue( "SenderTag", "Y" )

* Finaly send the email
loMaildoc.send( .F. )


jackyai 在 星期五 八月 19, 2005 6:22 pm 作了第 2 次修改
回頂端
檢視會員個人資料 發送私人訊息 MSN Messenger
garfield
Site Admin


註冊時間: 2003-01-30
文章: 2160


第 2 樓

發表發表於: 星期四 七月 28, 2005 9:10 pm    文章主題: 引言回覆

資料來源: http://fox.wikis.com/wc.dll?Wiki~LotusNotesEmail~SoftwareEng
I've seen a bunch of questions on VFP newsgroups about automating Lotus Notes using VFP, and found no explanations on this wiki, so I thought I'd create this page. This infomation posted by Dan Freeman is untested (by me) but was the clearest and most authoritative (sounding) I've seen. - wgcs


Lotus won't tell you this (in fact they go out of their way to hide the
fact) but Notes on the Windows platform is an automation server.

The following code will send e-mail from VFP using Notes:


*-- sending mail with Notes
*-- Assumes that it is sitting on a record to be processed
*-- for sending mail.
*-- message.cDomain is a Notes server/domain i.e. CAT01/CAT
*-- message.cUser is the location of a mail database i.e. "mail\user.nsf"
*-- message.cRecip is the recipient's e-mail address
*-- message.cSubject is the subject of the message
*-- message.mContents is the body of the message

oSpace = CreateObject("Notes.NotesUIWorkspace")

oSpace.OpenDatabase( TRIM(message.cDomain), TRIM(message.cUser) )
oDocument = oSpace.ComposeDocument(,,"Memo")

lcRecipient = message.cRecip
lcSubject = message.cSubject
lcContents = message.mContents

oDocument.FieldSetText("SendTo",lcRecipient)
oDocument.FieldSetText("Subject",lcSubject)
oDocument.FieldSetText("Body",lcContents)



Wim de Lange: I tried your code, but it didn't work for me. I use Lotus Notes 5. The following changes did the trick


oDocument.FieldSetText("EnterSendTo", lcRecipient)
*x oDocument.FieldSetText("SendTo",lcRecipient)
.
.
*x at the end
oDocument.Send()
oDocument.Close()


The only thing left, is how to enter passwords? Where can I find
an objectmodel for Lotus Notes?

--------------------------------------------------------------------------------

Heather Kidwell:

The NotesUIWorkspace example works, but if you want to generate an email without opening the client's GUI interface for Notes the NotesSession object can be used. The below example has been tested in versions 4 & 5 of Notes. Information on the object model for Lotus Notes can be found at http://www.lotus.com/products/lotusscript.nsf/R5?OpenNavigator.


*-- sending mail with Notes
*-- message.cDomain is a Notes server/domain i.e. CAT01/CAT
*-- message.cUser is the location of a mail databasei.e. "mail\user.nsf"
*-- message.cRecip is the recipient's e-mail address
*-- message.cSubject is the subject of the message
*-- message.mContents is the body of the message

*-- If your Notes directory is somewhere other than your current default
*-- setting I suggest you change the default prior to creating the
*-- NotesSession object. You can return to the previos default after
*-- the session object has been created

loSession = createobject("Notes.NotesSession")

*-- .GetDatabase creates a NotesDatabase object that represents the
*-- database located at the server and file name you specify, and opens
*-- the database, if possible.

loDB = loSession.GetDatabase(trim(message.cDomain), trim(message.cUser))

if loDB.isOpen()
*-- .CreateDocument() creates a document in a database and returns a
*-- NotesDocument object that represents the new document.

loMail = loDB.CreateDocument()

with loMail
*-- initialize the mail object's properties
.form = "Memo"

.sendTo = message.cRecip
.subject = message.cSubject
.body = message.mContents

.send()

endwith && loMail

endif && loDB.isOpen()



--------------------------------------------------------------------------------
.sendto = cRecip ... works great if you only have one recipient but use something like the following when multiple recipients are needed. I also included the variables for the cc and bcc recipients as well. NOTE: use an empty(' ') array element if there are no cc's or bcc's- AlekMassey



dime laNameTo(2),laCCto(1),laBCCto(1)
store ' ' to laCCto(1),laBCCto(1)
store 'AlekMassey@yahoo.com' to laNameTo(1)
store 'Alek_Massey@Teledyne.com' to laNameTo(2)

* LOMAIL created in the previous contributers' code
with lomail
.appenditemvalue('sendto',@laNameTo )
.appenditemvalue('copyto',@laCCto)
.appenditemvalue('blindcopyto',@laBCCto)
endwith




--------------------------------------------------------------------------------
Garth Almond: I've tried the above and it didn't work on Release 6.5 If you can use SMTP (its easier), if you can't and you have Notes 6.5 then try this



*------------------------------------------------------------
* SendEmail
*
* Sends Emails via Lotus Notes
*
* Parameters
* laSendTo array of character strings ("John Smith","jsmith@hotmail.com",...)
* laCC same as laSendTo
* laBCC same as laSendTo
* lcSubject character string ("Test Mail")
* lcBody character string ("Body of Test Mail")
* laAttachments array of character strings ("c:\printrep.xls","c:\preintrep2.xls",...)
*------------------------------------------------------------
PROCEDURE SendEmail
LPARAMETERS laSendTo, laCC, laBcc, lcSubject, lcBody, laAttachments
EXTERNAL ARRAY laSendTo, laCC, laBcc, laAttachments

LOCAL loSession && the note session to be oppened
LOCAL lcServer && notes server
LOCAL lcMaildbName && Mail db Name
LOCAL loMaildb && Mail db object
LOCAL loMailDoc && Document object, the email itself
LOCAL loStream && text stream used to attach a MIME document to the email object
&& i.e the Body of the object.

loSession = CREATEOBJECT( "Lotus.NotesSession" )
loSession.Initialize( )
* this will ask you for a password. A dialog will pop up for you to type it in
* or you can supply it programaticaly...
* loSession.Initialize( 'PASSWORD' )
* or use an email account without a password and you won't need to worry about it

* Get the default server and maildb for this PC from the Note Session
*lcServer = "dwim01/domgen"
*lcMaildbName = "mail\jsmith.nsf"
lcServer = loSession.GetEnvironmentString( "MailServer",.t.)
lcMaildbName = loSession.GetEnvironmentString( "MailFile",.t.)

* open the notes mail database
loMaildb = loSession.getdatabase(lcServer, lcMaildbName )
* create a document/email for the mail database
loMaildoc = loMaildb.CreateDocument()

* Who do we send it to
loMaildoc.ReplaceItemValue( "Form", "Memo" )
IF !EMPTY( laSendTo )
loMaildoc.ReplaceItemValue( "SendTo", @laSendTo )
ENDIF
IF !EMPTY( laCC )
loMaildoc.ReplaceItemValue( "CopyTo", @laCC )
ENDIF
IF !EMPTY( laBcc )
loMaildoc.ReplaceItemValue( "BlindCopyTo", @laBcc )
ENDIF

* The subject
loMaildoc.replaceitemValue( "Subject", lcSubject )

* The Body
loStream = loSession.CreateStream()
loStream.WriteText( lcBody )
* The Body MIME type
loBodyMime = loMailDoc.CreateMIMEEntity()
loBodyMime.SetContentFromText( loStream, "text/html;charset=iso-8859-1", .f. )

* Attachments
IF !EMPTY( laAttachments )
loRichTextItem = loMailDoc.CreateRichTextItem("Attachment")
FOR e = 1 TO ALEN( laAttachments )
loRichTextItem.EmbedObject(1454, "", laAttachments[e] )
NEXT
ENDIF

* this bit just me playing with the paper type and icons displaid in Notes.
* If its a propery in Notes then you can change it like this....
*(i.e. right click on the message, Document Proterties, 2nd tab...then experiment)
loMaildoc.ReplaceItemValue( "Logo", "StdNotesLtr3" )
loMaildoc.ReplaceItemValue( "_ViewIcon", 23 )
loMaildoc.ReplaceItemValue( "SenderTag", "Y" )

* Finaly send the email
loMaildoc.send( .F. )

RETURN

_________________
利用>>搜尋<<的功能會比問的還要快得到答案.
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
aqiang



註冊時間: 2004-02-28
文章: 26


第 3 樓

發表發表於: 星期五 八月 05, 2005 11:11 am    文章主題: 這個代碼會出錯 引言回覆

我一直想讓VFP可以直接 發MAIL給LOTUS 用戶 ,可是都不能成功 功力有限
_________________
★★★隨緣緣隨來 知福福常在 來自阿強的祝福★★★
回頂端
檢視會員個人資料 發送私人訊息
zlabsoft



註冊時間: 2003-10-18
文章: 22


第 4 樓

發表發表於: 星期三 八月 24, 2005 9:12 am    文章主題: 引言回覆

可試以附上的程式
回頂端
檢視會員個人資料 發送私人訊息 MSN Messenger
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作