VB icon

Send Outlook message from script

Email
Submitted on: 1/5/2015 12:00:00 PM
By: T Runstein (from psc cd)  
Level: Beginner
User Rating: By 16 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 7670
 
     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. 'T Runstein
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Send Outlook message from script
' Description: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. 'T Runstein
' By: T Runstein (from psc cd)
'
' Inputs:The script, as shown, is all hardcoded, but you could easily call "inputbox", 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 happy to help you customize it.
'
' Returns:You can choose to preview by using the .display, or send without preview by using .send
'
' Assumes:As with all .vbs scripts, you must have the scripting runtime. You also 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
'sub SendAttach() 
'Open mail, adress, attach report
dim objOutlk	'Outlook
dim objMail	'Email item
dim strMsg
const olMailItem = 0
'Create a new message
	set objOutlk = createobject("Outlook.Application")
	set objMail = objOutlk.createitem(olMailItem)
	objMail.To = "t_a_r@email.msn.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.attachments.add("C:\MyAttachmentFile.txt")
	objMail.body = strMsg
	objMail.display 'Use this to display before sending, otherwise call objMail.Send to send without reviewing
'Clean up
set objMail = nothing
set objOutlk = nothing
'end sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.