Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Automating Outlook w/VFP 8.0
Message
 
À
13/07/2005 10:34:46
Joseph Smith
The Ohio State University
Columbus, Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 8
OS:
Windows XP
Network:
Windows NT
Database:
Visual FoxPro
Divers
Thread ID:
01032221
Message ID:
01032739
Vues:
12
I sent emails from an unattended app as well and got tired of the Outlook popup. At one time I found a website that showed how to change the security settings in Outlook to bypass that dialog box, but it was a real pain. I decided to use CDO instead since it comes with Windows. Here's some example code:
lparameters tcTo, tcCC, tcBCC, tcFrom, tcSender, tcSubject, tcBody, tcAttachments, tlBodyIsHTML
local loConfiguration, loConfFields, loCDOMessage, llResult, laWord[1], x

llResult = .t.

*** Create and use the Microsoft Collaboration Data Objects (CDO) to send the email
*** CDO 1.2 was first available with Microsoft Exchange 5.5 and Windows NT® version 4. 
*** As of December 2003, CDO 1.2.1 is provided in Microsoft Outlook 98 and 2000. 
*** CDO 1.2.1 is also provided in Windows 2000 and Exchange 2000 for backwards compatibility. 

loConfiguration = createobject("CDO.Configuration")
if type("loConfiguration") <> "O"
	*- could not create Configuration object
	return .f.
endif

loCDOMessage = createobject("CDO.Message")
if type("loCDOMessage") <> "O"
	*- could not create CDO Message object
	return .f.
endif

loConfFields = loConfiguration.fields

With loConfFields
	.Item(cdoSMTPServer) = this.cSMTPServer
	.Item(cdoSendUsingMethod) = cdoSendUsingPort

	*** Extra SMTP Server settings that may be needed if your SMTP server require a username and password
	* Incoming Port = 110, Outgoing Port = 25
*!*			.Item(cdoSMTPServerPort) = 25
*!*			.Item(cdoSMTPAuthenticate) = cdoBasic
*!*			.Item(cdoSMTPAccountName) = "JoeShmo"

*!*			.Item(cdoSendUserName) = "JoeShmo"
*!*			.Item(cdoSendPassword) = "*****"
*!*			.Item(cdoSendEmailAddress) = "JoeShmo@yourcompany.com"

	.Update
Endwith

With loCDOMessage
	.Configuration = loConfiguration
	
	*- Multiple addresses are designated with a comma-separated list
	.To = tcTo	
	.CC = tcCC
	.BCC = tcBCC
	.From = tcFrom
	.Sender = tcSender
	.Subject = tcSubject
	
	*- Turn Message Disposition Notification ON to receive a Return Receipt for the email
	*- Actually, leave this off until we decide we will do something with return receipts
	*.MDNRequested = .t.
	
	*- Add body as either HTML or Plain Text
	if tlBodyIsHTML
		.AutoGenerateTextBody = .t.
		.HTMLBody = tcBody		
	else
		.MimeFormatted = .f.
		.Textbody = tcBody
	endif
	
	*- Add Attachments to email
	llResult = .AddAttachment("C:\Test\Test.txt")	
	
	llResult = .Send
Endwith

loCDOMessage = null
loConfiguration = null
loConfFields = null

return llResult
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform