Send Outlook message from script
This allows you to fill out and send an Outlook message from script. Uncomment 2 lines to create a sub that can be included in a larger script. Great for admins who routinely send reports.
2576 Since 25th November, 2003
Select and Copy the Code
' Name: Send Outlook message from script
' Description:This allows you to fill ou
' t and send an Outlook message from scrip
' t. Uncomment 2 lines to create a sub tha
' t can be included in a larger script. Gr
' eat for admins who routinely send report
' Inputs:The script, as shown, is all ha
' rdcoded, but you could easily call "inpu
' tbox", or read inputs off a form to fill
' in the items. If you need help adapting
' this to your needs, let me know - I'm ha
' ppy to help you customize it.
' Returns:You can choose to preview by u
' sing the .display, or send without previ
' ew by using .send
' Assumes:As with all .vbs scripts, you
' must have the scripting runtime. You als
' o need Outlook installed.
'Uncomment the sub and
'end sub lines to use this in a program.
'Leaving these commented will allow you
'to run this as a standalone script
'Open mail, adress, attach report
Dim objOutlk 'Outlook
Dim objMail 'Email item
Const olMailItem = 0
'Create a new message
Set objOutlk = CreateObject("Outlook.Application")
Set objMail = objOutlk.createitem(olMailItem)
objMail.To = "email@example.com"
objMail.cc = "" 'Enter an address here To include a carbon copy; bcc is For blind carbon copy's
'Set up Subject Line
objMail.subject = "I saw your code On Planet Source Code on " & CStr(Month(Now)) & "/" & CStr(Day(Now)) & "/" & CStr(Year(Now))
'Add the body
strMsg = "Your code rocks!" & vbCrLf
strMsg = strMsg & "I voted and gave you an excellent rating!"
'To add an attachment, use:
objMail.body = strMsg
objMail.display 'Use this To display before sending, otherwise call objMail.Send to send without reviewing
Set objMail = Nothing
Set objOutlk = Nothing