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

MAPI Mayhem

Status
Not open for further replies.

ahoodin7

Programmer
Jun 16, 2004
72
US
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
 
This works fine for me:

set olApp=WScript.CreateObject("Outlook.Application")
set mailitem=olApp.CreateItem(0)
set nameSpace = olApp.GetNameSpace("MAPI")

mailitem.Recipients.Add(acctname)
mailitem.Subject = mailsubject
mailitem.HTMLBody = mybody
mailitem.Importance = 2
mailitem.OriginatorDeliveryReportRequested = TRUE
mailitem.ReadReceiptRequested = TRUE
mailitem.Sensitivity = 3
mailitem.ReplyRecipients.Add("you@you.com")
mailitem.Recipients.ResolveAll
mailitem.Send
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top