Use specific account Exchange account to send from in vbsctipt
Please help me with my scripting problem. Here is the situation:
I have to send a message from specific email address from VBScript. I've got Exchange server 2003 and MS Outlook 2007 as an appplication if this matters.
My code is listed below. It works perfect but I sending out message only from my profile. How to use ns.Logon correctly to use another account or should I use something else instead of it?
Dim ol, ns, newMail
ToAddress = "email@example.com"
MessageSubject = "subject text"
MessageBody = "body"
MessageAttachment = "path_to_attachment"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "", "", true, false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.HTMLBody = MessageBody & vbCrLf
Set myRecipient = ns.CreateRecipient(ToAddress)
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
newMail.Attachments.Add(MessageAttachment).Display name = "name"
Set ol = Nothing