Wednesday, July 07, 2004

Sending a Mail via OWA from Script

Continuing on from some of my other posts I've done recently regarding reusing OWA commands such as this one I've come up with a script that uses the commands that OWA does to send a new email. Some of the advantages of this is that mail sent via this method ends up in the sent items of the sending mailbox. Its also acts as an alternative where you don't want to use CDO, ADO/Exoledb or WebDAV.

stmsgbody ="Hello Fred <BR<BR>"
stmsgbody = stmsgbody & "What to get some coffee Mate, Meet me downstairs in ten<BR><BR>"
stmsgbody = stmsgbody & "Cheers<BR>"
stmsgbody = stmsgbody & "Barney<BR>"
szXml = ""
szXml = szXml & "Cmd=send" & vbLf
szXml = szXml & "" & vbLf
szXml = szXml & "MsgCc=" & vbLf
szXml = szXml & "MsgBcc=" & vbLf
szXml = szXml & "urn:schemas:httpmail:importance=1" & vbLf
szXml = szXml & "" & vbLf
szXml = szXml & "urn:schemas:httpmail:subject=Coffee ???" & vbLf
szXml = szXml & "urn:schemas:httpmail:htmldescription=<!DOCTYPE HTML PUBLIC " _
& """-//W3C//DTD HTML 4.0 Transitional//EN""><HTML DIR=ltr><HEAD><META HTTP-EQUIV" _
& "=""Content-Type"" CONTENT=""text/html; charset=utf-8""></HEAD><BODY><DIV>" _
& "<FONT face='Arial' color=#000000 size=2>" & stmsgbody & "</font>" _
& "</DIV></BODY></HTML>" & vbLf
Set ObjxmlHttp = CreateObject("Microsoft.XMLHTTP")
ObjxmlHttp.Open "POST", "http://yourserver/exchange/yourmailbox/Drafts", False, "",""
ObjxmlHttp.setRequestHeader "Accept-Language:", "en-us"
ObjxmlHttp.setRequestHeader "Content-type:", "application/x-www-UTF8-encoded"
ObjxmlHttp.setRequestHeader "Content-Length:", Len(xmlstr)
ObjxmlHttp.Send szXml
Wscript.echo ObjxmlHttp.responseText


Anonymous said...

can u tell me how i can run this??

Glen said...

Its a script configure the varibles in the

ObjxmlHttp.Open "POST", "http://yourserver/exchange/yourmailbox/Drafts", False, "","

and then run it using cscript im not sure how i can better answer this.

Anonymous said...

hey thanks for replying... i configured the variables and when i run it with cscript i get the following error..

"Bad Request (Invalid Verb)"

Anonymous said...

can you please let me know if you have any script which will send a mail using OWA using cscript??

Glen said...

Invalid verbs a pretty strange error what you might want to try to do is use Etheral to do a packet capture when you send a message in OWA this will give the correct format of the XML you need to send. Otherwise you might want to look at the WebDAV method from the SDK

Anonymous said...

this works!!! Thanks a ton.. :)

Anonymous said...

How do you authenticate to OWA? There doesn't seem to be a place for your password?

Glen said...

This script uses NTLM so it will use the context of the whatever is executing it. You can hardcode the username and password in the following line.

ObjxmlHttp.Open "POST", "http://yourserver/exchange/yourmailbox/Drafts", False, "domain\user","password"

This will only work if you server is using NTLM or basic authentication if your using Forms Based Authentication you need to look at something like


Tarique Waseem said...

hi glen

i am using webdav method to delete the recurring appointment from the calendar it is working but sometime it does not delete all the event given date range
and in the second attempt it delete all the events between date range

sometime when i manually delete a single recurrence of an event it gives an error

500 internal server error

please help me

thanks in advance

Tarique Waseem

Glen said...

Because of the way exchange stores recurrences (recurrences are stored as attachments on the master instance of the appointment). There is no supported method to modify or delete recurrences using WebDAV. If you delete the instance via WebDAV they may disappear in OWA but they will still be their in Outlook. An if the appointment gets re-expanded then they will just reappear. The only supported method of modifying or deleting recurrences is to use Mapi or CDOEX. Or if you using Exchange 2007 then use EWS.