A Small Script (Send E-Mail via the Outlook Object Model)

Originally published June 21, 2004

 

I got this small basic script from a article by Mark Hardy [mark.hardy@parys-snowdon.co.uk], who also said he didn't know where he got his original script from. I cleaned it up just a tad.

To get around the Outlook “guard“ where it requests your permission to send the email, I recommend Express ClickYes. It's free and it works. Google for it, to download it. One place that normally has it is: http://www.snapfiles.com/get/clickyes.html

Option Explicit
'On Error Resume Next

' Microsoft Outlook object variables.
Dim myolApp, olNameSpace, myFolder, myMailItem

' Try to create an MSOutlook object
Set myolApp = CreateObject ("Outlook.Application")
' Set up MAPI name space for mailing
Set olNameSpace = myolApp.GetNameSpace ("MAPI")
' Create a mail item
Set myMailItem = myolApp.CreateItem (0)
' Set up mail recipient.
myMailItem.To = “someone@domain.com"
' Set message subject.
myMailItem.Subject = "Test Email"
' Set the body of the message
myMailItem.Body = "Email sent"
' Send mail to recipients
myMailItem.Send

' clean up
Set myMailItem  = Nothing
Set olNameSpace = Nothing
Set myolApp     = Nothing

Published Tuesday, November 13, 2007 5:27 PM by michael
Filed under:

Comments

No Comments