Communicate with an Exchange Server 2003 mailbox - exchange-server

I'm searching for some way to gain access to an Exchange Server 2003 mailbox
using XMLHttpRequest in order to render folders like Inbox, etc... on my page.
I know I have to include credentials in my url passing process, but I don't know how to
specify that. Is there a way or some example of doing so to get some XMLResponse from the server?

This Microsoft support article How to programmatically get the size of mailboxes in Exchange contains code samples, and might be a place to start. Also, How to send a simple e-mail by using XMLHTTP and WebDAV in Visual Basic .NET
This code snippet shows the basic pattern of sending a request:
strURL = "http://" & strExchangeServerName & "/Exchange/" & strMailboxName & "/" &
strFolderName
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "DELETE", strURL, False, strUserName, strPassword
objXMLHTTP.setRequestHeader "Depth", "infinity,noroot"
objXMLHTTP.Send()

Related

Windows 2008 script error when mail server offline

Everything works perfectly until our mail server goes offline. But when the mail server cannot be reached our scripting fails. When a user logs into the website th server sends a notice to admin by email. But if the mail server is offline that login fails and returns a server error.
We are using CDOSYS and using the local SMTP server to relay to our main mail server. The code is straightforward...
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = artiscart_mail_server
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = strEmail
ObjSendMail.Subject = "Login activity"
ObjSendMail.From = strEmail
ObjSendMail.TextBody = strEmailBody
ObjSendMail.Send
Set ObjSendMail = Nothing
A similar thing happens when we send a newsletter and one of the emails is a dud. On Windows Server 2003 we had no problems whatsoever, but on Windows Server 2008 the same scripting fails.
Is there some way that I can configure the local SMTP server to ignore errors and move on?
To avoid all errors caused by mail server failure and bad email addresses, simply add this first line above the last line like so...
On Error Resume Next
ObjSendMail.Send

Retrieiving Cookies and Sending Cookies and Post Variables in VBScript

I'm trying to submit some post data form using vbscript. The site I'm posting it to contains some java, and having poked around in the headers, I notice it's sending a cookie containing JSESSIONID, which I believe is to do with the java authentication:
Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX
When I just send the address and the post data I want to send and look at the responsetext it's sent me back to the java authentication page, which makes me think I need to retrieve the jsessionid cookie and submit that back with the data as well.
This is the function I'm using to submit the post data. For simple forms this seems to work fine, but the java on this page has kind of thrown me:
Function Fetch(URL, POST)
Set WshShell = CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
http.open "POST", URL, FALSE
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send POST
Fetch = http.responseText
set WshShell = nothing
set http = nothing
End Function
My questions really are: am how doing this right? Do I need to load the first page, get the cookie and resubmit it back with the form? And if so, how do I retrieve the cookie that the server sends back in the header? I can see when I look in the headers that they sent back:
Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page
Thanks very much.
You could get via http.getResponseHeader("Set-Cookie") or parsing http.getAllResponseHeaders(). Then, you should add cookie values to request header via http.setRequestHeaders "Cookie", "JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/Page" on next requests.
So, there is another option (if i'm not wrong), using CreateObject("WinHttp.WinHttpRequest.5.1").
It's capable to remember the cookies had previously to use on next requests as long as you use the same instance.

VBScript to send email without running Outlook

I have written an automated test that runs each night, and I would like to email the results each night once the test is finished.
In order to do this I attempted to put the following at the end of my batchfile:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "a#a.com"
.Subject = "Subject"
.ReadReceiptRequested = False
.HTMLBody = "resport"
End With
MyItem.Send
However, this is causing the email to not send because my Outlook is not open, as the test is run in the background, and I have no access to the UI.
Is there anyway to send this email without actually running outlook on the machine.
Thanks!
You can send email without Outlook in VBScript using the CDO.Message object. You will need to know the address of your SMTP server to use this:
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Subject"
MyEmail.From="name#domain.com"
MyEmail.To="a#a.com"
MyEmail.TextBody="Testing one two three."
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
If your SMTP server requires a username and password then paste these lines in above the MyEmail.Configuration.Fields.Update line:
'SMTP Auth (For Windows Auth set this to 2)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username"
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"
More information on using CDO to send email with VBScript can be found on the link below:
http://www.paulsadowski.com/wsh/cdo.htm
Yes. Blat or any other self contained SMTP mailer. Blat is a fairly full featured SMTP client that runs from command line
Blat is here

Coldfusion sessions - how exactly is CF identifying a connection / unique client

Coldfusion sessions - how exactly is CF identifying a connection / unique client
After doing some digging with remote CFCs I called from Word VBA I found they set sessions also. Which got me to thinking and Googling (unsuccessfully) for an explanation of just how CF does distinguish between different clients. I had previously assumed it was a browser cookie being set to identify the client, but then here I was consuming a web service through a word app and still getting the session variables and sessionID set.
So if I load and login to my app via browser (chrome) and hit a test page I get jsessionID = 123,If I fire up firefox and login I get a different jsessionid = 234 as expected. If I hit a remote cfc as a web service wsdl using Word VBA I can see jsessionid=345 returned to the VBA module. If I close Word and reopen my macro (containing a login request to the web service) I get a new jsessionID=567
So what is it about the request that CF is identifying and how does it persist the identification of the client?
This is the same issue in a VBA http call
Sub doHTTP()
Dim MyRequest As Object
Dim Val
httpString = "http://localhost:8888/test.cfm"
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", httpString
' Send Request.
MyRequest.Send
MsgBox MyRequest.ResponseText
'now pass in the session urltoken we have just retreived
MyRequest.Open "GET", httpString & "?urltoken=" & MyRequest.ResponseText
' resend a request, this time with the urltoken.
MyRequest.Send
'take a look and see if the session variables are correct
MsgBox MyRequest.ResponseText
End Sub
in a test.cfm
<cfif isdefined("URL.urltoken")>
<cfset session.urltoken="#URL.urltoken#">
<cfelse>
<cfset session.username="bob">
</cfif>
<cfoutput>session.urltoken="#session.urltoken#"</cfoutput><br>
<cfoutput>session.username="#session.username#"</cfoutput><br>
<cfoutput>session.sessionID="#session.sessionID#"</cfoutput>
OK that now works, interesting, I will need to remember for web service or http calls not using a browser I will need to pass the sessionID in the URL manually.
Definitely session maintained based on browser cookie. On first request from browser server assign token and this will used to make session connection in rest of the request. If browser cookies are disabled then you may need it pass CFID and CFTOKEN in URL for every request and in case of j2ee session management you may need to pass jsessionId as well (best way is to append session.URLToken in every request.)
In word macro you get new jsessionId because word may not have cookie and not able to persist connection but just try to concat session.URLToken in next Webservice call and you will get all your session back even after reopening word or even you can try copy session.URLToken from chrome browser request and append it in firefox request and you will get same session available in Chrome (same thing will work if you trying from different computer as well).
So moral of story is combination of CFID,CFTOKEN,JSessionId(in case of J2ee session management) use for connection between client and server either through URL or Cookie.

How to POST HTTPS request using VBScript

I want to know how to make a HTTPS request from a VBScript client.
After receiving the request, how to decrypt the HTTPS response?
HTTPS is not just an encryption format - it's a transport security protocol, with complex negotiation built-in. Just like you wouldn't try to build an HTTP client component in VBScript, similarly you wouldn't try to build an HTTPS/SSL client.
The VBScript language doesn't include any HTTP or HTTPS client, but windows has a couple of COM objects that can be used (from Windows Script Host of from ASP pages written in VBScript), and VBScript code running in internet explorer can similarly access a browser object that allows HTTPS calls.
From windows (WSH/ASP), the best object is typically MSXML2.ServerXmlHTTP, for example see this quick overview: http://www.developerfusion.com/article/3272/posting-form-data-to-a-web-page/2/
From Internet Explorer, as long as you're not dealing with legacy versions, the best idea is to use the cross-browser standard object XMLHttpRequest. The following page gives you an overview: http://www.jibbering.com/2002/4/httprequest.html
All of these HTTP clients also support HTTPS.
dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP")
xHttp.Open "GET", "https://yourhost.example.com/foo", False
' 2 stands for SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS
' 13056 means ignore all server side cert error
xHttp.setOption 2, 13056
xHttp.Send
' read response body
WScript.Echo xHttp.responseBody
Reference:
getOption Method of XML DOM
setOption Method of XML DOM

Resources