VBS Script to send email using specified exchange account
Hello all
I have a vbs script which sends an email using the default outlook account on the machine. The problem i have is that not everyone who uses the script will have an outlook profile setup beforehand, but they will have an exchange profile. I need a way to send the email by specifying the accound details to use.
This is what i have so far:
Code:
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "Recipients Address"
MessageSubject = "Subject"
MessageBody = "Message Body"
MessageAttachment = "Attchment Path"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Send
End If
Set ol = Nothing
I just need help specifying the exchange account (i am making the vbs script on the fly with another application so the username and password for the account can be written in if required)
Does anyone know if this is possible??
Thanks