LeightonJames Posted March 18, 2010 Posted March 18, 2010 (edited) 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: Dim ToAddress Dim MessageSubject Dim MessageBody Dim MessageAttachment Dim ol, ns, newMail ToAddress = [b]"Recipients Address"[/b] MessageSubject = [b]"Subject"[/b] MessageBody = [b]"Message Body"[/b] MessageAttachment = [b]"Attchment Path"[/b] 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 Edited March 18, 2010 by LeightonJames found the attachment code!!
box_l Posted March 22, 2010 Posted March 22, 2010 Have you looked at CDO? Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Example Message" objMessage.From = "[email protected]" objMessage.To = "[email protected]" objMessage.TextBody = "Sample text." objMessage.Send Use variables for the user and domain parts. no need for outlook profiles this way. BoX
LeightonJames Posted March 23, 2010 Author Posted March 23, 2010 i thought CDO only worked for smtp?? It needs to be sent using MAPI as it's going through an exchange server. If this works then great but how can i add an attachment using this method?
apeo Posted March 23, 2010 Posted March 23, 2010 i thought CDO only worked for smtp?? It needs to be sent using MAPI as it's going through an exchange server. If this works then great but how can i add an attachment using this method? Why cant you send it via smtp when going through an exchange server? To add attachment: objMessage.AddAttachment "c:\temp\attachment.txt"
LeightonJames Posted March 23, 2010 Author Posted March 23, 2010 (edited) because i know zip about vbs coding and how to structure the server details. if anyone can help me then it would be greatly appreciated. EDIT: just a thought but using this method results in the email not actually being authenticated as such and going through a "back door" on the server. If i use this method for sending the emails in my Application i think my Bosses might have something to say about it. Thanks for all the help but i will stick with my having to need a profile method for now. Edited March 23, 2010 by LeightonJames
box_l Posted March 23, 2010 Posted March 23, 2010 maybe try something like: ns.Logon("outlook-username", "outlook-password", false, true) BoX
LeightonJames Posted March 24, 2010 Author Posted March 24, 2010 stupid question i know but what does that do??
box_l Posted March 24, 2010 Posted March 24, 2010 ns.logon "[email protected]","password",true,false seems to work for me. you already have ns.logon "","",true,false in your code. try it, see what happens. BoX
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now