Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Outlook and Scripting 2

Status
Not open for further replies.

Reyn

MIS
Dec 11, 2002
20
US
As someone new to scripting I am at a loss on this one... Is the anyway to take the contents of a text file and have it automatically placed in the body of a new outlook email message, not as an attachment, but as the text of the message. Thanks!
 
On a recurring basis, or just once? If it's a recurring basis, I'm inclined to say importing that text file into an Outlook signature would probably work.

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Want to know how email works? Read for yourself -
 
signature posts sounds like a winner...

other than that i would guess one could change the OnLoad event of the default mail form to include code that runs off and looks at a text file and chucks it in the message
 
Keep in mind that if users are doing digital signing using a cert, that chucking things into the message after the user whacks the send button will break the digital signature.

Pat Richard, MCSE MCSA:Messaging CNA
Microsoft Exchange MVP
Want to know how email works? Read for yourself -
 
Yes, you can do this. You have two options.

Create and SMTP message using CDO which is very simple and doesnlt actually require outlook.

If you do specifically want to use Outlook, then you can do that too.

Here is a simple CDO example. Note you can read the contents of your text file to be used in the body instead of using the hard coded technique shown,
Code:
Set objEmail = CreateObject("CDO.Message")

objEmail.From = "monitor1@fabrikam.com"
objEmail.To = "admin1@fabrikam.com"
objEmail.Subject = "Atl-dc-01 down" 
objEmail.Textbody = "Atl-dc-01 is no longer accessible over the network."
objEmail.Send

And a sample for sending via Outlook
Code:
'==========================================================================
'
' NAME: SendOutlookEmail.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 1/21/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT: 
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'==========================================================================

Dim objOL, objEmail, strMsg
Const olMailItem = 0

'Create a new message
Set objOL = CreateObject("Outlook.Application")
Set objEmail = objOL.createitem(olMailItem)

'Address the message
objEmail.To = "DestinationEmailAddress@company.com"
'Uncomment the following two lines and include email addresses for CC and BCC
'objEmail.cc = "" 
'objEmail.bcc = "" 

'Set up Subject Line
objEmail.subject = "Message subject text goes here"

'Add the body
strMsg = "Body text goes here" & vbcrlf
objEmail.body = strMsg

'Use the following to add an attachment
'objEmail.attachments.add("C:\Folder\AttachmentFileName.txt")

'objEmail.display 'Use this to display the message before sending. 
'(comment out next line if using display)
objEmail.Send

'Clean up
Set objEmail = nothing
Set objOL = nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
A Big thanks to all of you, this really helped!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top