Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MAPI Text Format
Message
De
07/03/2003 11:20:57
 
 
À
06/03/2003 15:11:56
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00761820
Message ID:
00762772
Vues:
17
Hi Steve,

I'm posting a simple function to send a MAPI email. It should work with Outlook, Eudora, ..., there is no change in the function. To send a HTML message, you only have to pass a HTML string trough the cBody parameter (don't use your HTML code as the attachment).
I use a editBox with HTML code, so that the user can modify it before sending, and pass the editBox.value
And sometimes I generate a file with textmerge and then pass the string with fileToStr().
******************************************************************************
*-- Sends a mail through MAPI.
*-- Parameter cAttach has to be a full path file name.
******************************************************************************
function sendMAPIMail(cSubject, cBody, cRecipient, cAttach)
local lcDirectory, loMAPISession, loMAPIMessage

do case
case pCount() < 3
	*-- Include here your favorite message
	return .f.
case pCount() < 4
	cAttach = ''
endcase

*-- The MAPI server can change the directory if it has to be initialized
lcDirectory = set('directory')

loMAPISession = createObject('MSMAPI.MAPISession.1')
loMAPIMessage = createObject('MSMAPI.MAPIMessages.1')

*-- Signon procedure
with loMAPISession
	.Signon()
	*-- Checks that the session has been initialized, and assigns the id
	*-- to the message object
	if (.SessionID > 0)
		loMAPIMessage.SessionID = .SessionID
	else
		wait window "Could not initalize MAPI session"
		return .f.
	endif
endwith

*-- Sends the message
with loMAPIMessage
	.Compose()

	.RecipDisplayName = allTrim(cRecipient)
	.RecipType = 1
	.ResolveName()

	.MsgSubject = allTrim(cSubject)
	.MsgNoteText = allTrim(cBody)
	
	*-- Attach the file to the message. You can attach several files
	*-- by only adding a FOR...ENDFOR that loops through the files
	*-- in the attach string, or yu can modify the function to pass
	*-- an array of file names
	if NOT isBlank(cAttach) AND file(cAttach)
		.AttachmentIndex = loMAPIMessage.AttachmentCount
		.AttachmentName = right(cAttach, len(cAttach) - rat('\', cAttach))
		.AttachmentPathName = cAttach
	endif

	.Send(.f.)
 endwith

loMAPISession.Signoff()
set directory to (lcDirectory)

return .t.
This is a very simple function and you can improve it in many ways, but it shows a simple way to use MAPI to send a message.

Regards,
Javier.

>Hello Javier,
>
>Can you post a code example that will send an HTML message with Eudora as the MAPI server?
>
>I'm sure some folks would find it helpful.
>
>Thanks...
>
>>Hi Steve,
>>
>>I was the one who claimed it can be done in Eudora. I have been using it everyday since Eudora 4 came to market (I guess about 2 years ago). I didn't know MAPI could not work with HTML, so I tried it and it worked.
>>
>>Regards,
>>Javier.
>>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform