PDA

View Full Version : Message Attachments (W2K)



dbradbury
07-01-2002, 09:19 AM
Hi All

I am looking to create a script that creates an e-mail (successfully done) with Outlook. So far it uses a specified profile but still comes up with the warning that a program is trying to automatically send an email. The query that I have is that I cannot get files attached to the message (serious headache!!). Any methods, samples or advice would be appreciated.

Dave

jarenth
07-03-2002, 02:27 PM
If you are looking for a quick and easy .vbs script that will send an email and automatically attach files using Outlook, you can use the follwing script template:

'Begin Script
Set WshShell = CreateObject("WScript.Shell")


Const olMailItem = 0

Dim objOutlook
Dim objNameSpace
Dim mItem
Dim strReceipient
Dim strSubject
Dim strBodyText
Dim strMsg
Dim pAttachment
Dim strAttach1
Dim strAttach2

strReceipent = "To Who?"
strSubject = "Your Subject here"

strAttach1= "C:\test.txt"
strAttach2= "C:\winnt\test.log"

Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set mItem = objOutlook.CreateItem(olMailItem)

mItem.To = strReceipent
mItem.Subject = strSubject
mItem.Body = strBodyText

If Len(strAttach1) > 0 Then
Set pAttachments = mItem.Attachments
pAttachments.Add strAttach1
End If

If Len(strAttach2) > 0 Then
Set pAttachments = mItem.Attachments
pAttachments.Add strAttach2
End If

mItem.Save
mItem.Send



If strReceipent = "" Then
Msgbox "No Receipient provided. Mail not sent", vbInformation,"Mail Error"
End If



' **** Clean up
'
Set mItem = Nothing
Set objNameSpace = Nothing
set objOutlook = Nothing

'End Script

Outlook 2002 requires intervention to ok the email to be sent due to a security setting.

hope this helps.