Use specific Exchange account to send message from in vbsctipt

Author Message
dorofeevdima

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 12/27/2011
  • Status: offline
Use specific Exchange account to send message from in vbsctipt Tuesday, December 27, 2011 10:45 PM (permalink)
0
Hi all,

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 ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment

Dim ol, ns, newMail

ToAddress = "someone@domain.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)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Attachments.Add(MessageAttachment).Display name = "name"
newMail.Recipients.Add(CCAddress)
newMail.Send
End If

Set ol = Nothing
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Use specific Exchange account to send message from in vbsctipt Tuesday, January 03, 2012 2:24 AM (permalink)
    0
    When in doubt, read the documentation. If you want to use a different profile, you need to specify the profile and its password.
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9