*------------------------------------------------------------
* SendEmail
*
* Sends Emails via Lotus Notes
*
* Parameters
* laSendTo array of character strings ("John Smith","
[email protected]",...)
* 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