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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attachments in VB script

Status
Not open for further replies.

TheNewOne

Technical User
Mar 27, 2004
117
SI
Hi everyone. I have a problem with Attachments in script wich sends email. I use Outlook 2000, and my script looks like this:

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
Dim dtmCurrentDate
dtmCurrentDate = Date
ToAddress = "myname@myhome.com"
MessageSubject = "Free disk space report: "
MessageBody = ""
MessageAttachment = "c:\DiskReport jtomazic " _ &dtmCurrentDate & ".txt"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send

I know how to send 1 Attachment in this script, but i want to send 4 attachments. Any advice how to solve this problem?? Thx
 
Have you tried changing the value of MessageAttachment and doing this line again:

newMail.Attachments.Add(MessageAttachment)

Since it is using the Add method, then I would assume the newMail object is treating the attachments as a collection in which case you should be able to keep adding as many as you'd like.
 
Here is one I use just about every day
Enjoy Bob

Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim MessageAttachment2
Dim MessageAttachment3
Dim MessageAttachment4
Dim ol, ns, newMail
ToAddress = "someone@email.com"
MessageSubject = "your files"
MessageBody = "special files"
MessageAttachment = "c:\folder\cindy\adds.txt"
MessageAttachment2 = "c:\folder\cindy\hits.txt"
MessageAttachment3 = "c:\folder\cindy\dels.txt"
MessageAttachment4 = "c:\folder\cindy\carsup.rpt"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Attachments.Add(MessageAttachment2)
newMail.Attachments.Add(MessageAttachment3)
newMail.Attachments.Add(MessageAttachment4)
newMail.Send

 
Thx guys for your help. You relly rock.

Jure from Slovenija
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top