I wrote this vbScript to create an email, attach a document and send it. The email goes to the outbox, and doesnt get sent until someone opens Outlook and clicks Send/Receive. I am at a loss to say why I can't automate this. Can anybody provide help? I don't usually do this vbs but every once in a while you gotta do what u gotta do.
Yes this has to be a client side script and no I dont have access to the web server/email server.
Following is the code I used.
FWIW,
ahoodin
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns
newMailToAddress = "addr1@mail.com"
ToAddress2 = "addr21@mail.com"
MessageSubject = "AUTOMATED MAIL TEST Flow Data"
MessageBody = "*BODY* Data *BODY*"
set ol = WScript.CreateObject("Outlook.Application"
set ns = ol.getNamespace("MAPI"
ns.logon "Microsoft Outlook Internet Settings","",true,falseset
newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
MessageAttachment = "c:\windows\desktop\data.xls"
' validate the recipient, just in case...
set myRecipient = ns.CreateRecipient(ToAddress)
set my2Recipient = ns.CreateRecipient(ToAddress2)
myRecipient.Resolve
If Not myRecipient.Resolved then
MsgBox "unknown recipient"
else
my2Recipient.Resolve
If Not myRecipient.Resolved then
MsgBox "unknown recipient2"
else
newMail.Recipients.Add(myRecipient)
newMail.Recipients.Add(my2Recipient)
newMail.Attachments.Add(MessageAttachment)
.Displayname = "Spread Sheet"
newMail.Send
End If
End If
ns.Logoff
set ol = nothing
set ns = nothing
Yes this has to be a client side script and no I dont have access to the web server/email server.
Following is the code I used.
FWIW,
ahoodin
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns
newMailToAddress = "addr1@mail.com"
ToAddress2 = "addr21@mail.com"
MessageSubject = "AUTOMATED MAIL TEST Flow Data"
MessageBody = "*BODY* Data *BODY*"
set ol = WScript.CreateObject("Outlook.Application"
set ns = ol.getNamespace("MAPI"
ns.logon "Microsoft Outlook Internet Settings","",true,falseset
newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
MessageAttachment = "c:\windows\desktop\data.xls"
' validate the recipient, just in case...
set myRecipient = ns.CreateRecipient(ToAddress)
set my2Recipient = ns.CreateRecipient(ToAddress2)
myRecipient.Resolve
If Not myRecipient.Resolved then
MsgBox "unknown recipient"
else
my2Recipient.Resolve
If Not myRecipient.Resolved then
MsgBox "unknown recipient2"
else
newMail.Recipients.Add(myRecipient)
newMail.Recipients.Add(my2Recipient)
newMail.Attachments.Add(MessageAttachment)
.Displayname = "Spread Sheet"
newMail.Send
End If
End If
ns.Logoff
set ol = nothing
set ns = nothing