Jump to content

Recommended Posts

Posted (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 by LeightonJames
found the attachment code!!
Posted

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

Posted

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?

Posted
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"

Posted (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 by LeightonJames

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...