This is a discussion on Send Mail From Outlook Web Access within the PHP Language forums, part of the PHP Programming Forums category; After hours and hours of frustration, I got it to work! Got it started in Linux Bash with curl. Also ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
After hours and hours of frustration, I got it to work! Got it started
in Linux Bash with curl. Also used Squid and Mozilla with Squid as proxy in order to identify all the URLs. One can easily convert the following to PHP if they know a little PHP. They can also use the $result=`command`; to get it done that way. This also circumvents the Microsoft security stuff that prevents one from doing the same thing with CDO code on a Windows box. If you all can shorten this script down from a better hack -- I'd love to see your examples. #!/bin/bash # Script to connect Linux to OWA 5.5 (perhaps works with later revs) # to send an email on behalf of some user. # Note for some reason this won't work if you have the Outlook client open. # Doesn't seem to mind if OWA is open, though. # Note you can remove some curl switches below to not have any debug # traffic show up on your console when you run this as a test. # Note this example assumes it's http instead of https -- change this if # otherwise in your environment. DOMAIN=DISNEYWORLD USER=mmouse PASS=dontguessit LASTNAME=Mouse FIRSTNAME=Mickey EMAIL_TO="mickey_mouse@disneyworldland.com" EMAIL_CC="" EMAIL_BCC="" EMAIL_SUBJECT='This is a test' EMAIL_MSG='This is the test message.' EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/ /%20/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/ /%20/g'` rm -f *.asp rm -f *.txt curl -y 15 -o logon.asp -c cookies.txt http://webmail/exchange/logon.asp # why I have to do the following twice is beyond my recognition -- might # have to do with timing?? curl -y 15 -v -o logonfrm.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS http://webmail/exchange/LogonFrm.asp?isnewwindow=0\&mailbox=$LASTNAME%20$F IRSTNAME curl -y 15 -v -o logonfrm.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS http://webmail/exchange/LogonFrm.asp?isnewwindow=0\&mailbox=$LASTNAME%20$F IRSTNAME curl -y 15 -v -o root.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS http://webmail/exchange/root.asp curl -y 15 -v -o nbinbox.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS http://webmail/exchange/Navbar/nbInbox.asp curl -y 15 -v -o main_fr.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS 'http://webmail/exchange/inbox/main_fr.asp?view=1&store=0&obj=&acs=' OBJID=$(cat main_fr.asp | grep -i "var szCurFolderID" | cut -f 4 -d " " | cut -f 2 -d "\"" | tr -d "\n") curl -y 15 -v -o peerfldr.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://webmail/exchange/inbox/peerfldr.asp?obj=$OBJID&store=0" curl -y 15 -v -o commands1.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS 'http://webmail/exchange/inbox/commands.asp?command=nothing&store=0' curl -y 15 -v -o messages.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://webmail/exchange/inbox/messages.asp?obj=$OBJID&store=0" curl -y 15 -v -o title.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://webmail/exchange/inbox/title.asp?obj=$OBJID&acs=&compidx=0&store=0" curl -y 15 -v -o frmroot.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS 'http://webmail/exchange/forms/ipm/note/frmroot.asp?command=new&store=0' MSGID=$(cat frmroot.asp | grep -i "+\"&obj=" | cut -f 2 -d "=" | cut -f 1 -d "\"" | tr -d "\n") curl -y 15 -v -o cmptitle.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS 'http://webmail/exchange/forms/ipm/note/cmpTitle.asp?tab=1&att=0&imp=1' curl -y 15 -v -o cmpmsg.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://webmail/exchange/forms/ipm/note/cmpMsg.asp?obj=$MSGID&caller=1" curl -y 15 -v -o commands2.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://webmail/exchange/forms/ipm/note/commands.asp?obj=$MSGID" curl -y 15 -v -o commands3.asp -b cookies.txt -u $DOMAIN\\$USER:$PASS -d "to=$EMAIL_TO&cc=$EMAIL_CC&bcc=$EMAIL_BCC&subject= $EMAIL_SUBJECT&message=$EMAIL_MSG&tab=message&comm and=send&objID=$MSGID&savecopy=1&importance=1" "http://webmail/exchange/forms/ipm/note/commands.asp" curl -y 15 -v -o logoff.asp -b cookies.txt -u "$DOMAIN\\$USER:$PASS" 'http://webmail/exchange/logoff.asp' |
|
|||
|
An even better version...
#!/usr/bin/bash # filename: send2owa # send2owa -- Send Message From Linux To Exchange Server Via Outlook Web Access # Public Domain # The anonymous author designed this so that Linux-based business system batch job status reports could be sent to Outlook clients in a corporate environment where SMTP was banned and Exchange Server was the only thing enabled. # /note/ This is programmed for Exchange 5.5 -- may need mods for other revs of OWA. If you need to modify, consider using Squid with query params turned on and point your browser to this proxy. That way, you can see the web server interaction of GETs and POSTs and can tweak this script per your needs. # Note Microsoft calls itself interoperable but this API below is not explained # and they want you to go through the even more convoluted WebDAV technique. Note how interoperable Linux is! # Note that you can't use CDO API in VB anymore without all these security alerts popping up, leaving us with no choice but to go this route! # Possible improvement suggestion -- build a fake SMTP service in your favorite Linux language that then uses send2owa to send the message to the Exchange server. This permits you to use ordinary SMTP tools with your corporate development and operations teams in order to send mail out. if [ "$1" == "-i" ]; then INTERACTIVE="TRUE" fi if [ "$1" == "-h" ]; then NEEDSHELP="TRUE" fi if [ "$1" == "--help" ]; then NEEDSHELP="TRUE" fi if [ "$1" == "-?" ]; then NEEDSHELP="TRUE" fi if [ "$1" == "/?" ]; then NEEDSHELP="TRUE" fi if [ "$1" == "" ]; then NEEDSHELP="TRUE" fi if [ $NEEDSHELP ]; then echo -e "send2owa $VERSION: Send Message From Linux To Outlook\n" echo -e "Usage: send2owa [-i | {strict options order}]\n" echo -e "\t-i =\t\t\t Interactive. Prompts you for everything." echo -e "\t{strict options order} = Non-interactive. Requires options in following order." echo -e "\n\tNote: \"Quoting\" your options is REQUIRED.\n" echo -e "\t\t<Your Outlook Webmail Host Name>" echo -e "\t\t<Your Domain>" echo -e "\t\t<Your Username>" echo -e "\t\t<Your Password>" echo -e "\t\t<Your First Name>" echo -e "\t\t<Your Last Name>" echo -e "\t\t<Your Recipient Email Address List (Semicolon Delimited)>" echo -e "\t\t<Your CC Email Address List (Ditto)>" echo -e "\t\t<Your BCC Email Address List (Ditto)>" echo -e "\t\t<Email Subject>" echo -e "\t\t<Email Message>\n" echo -e "Ex:\n" echo -e "./send2owa 'webmail' 'rook' 'jsmith' 'Pass1' 'Jack' 'Smith' 'dhenry@gadgets.bv' '' '' 'Hello, World!' 'This is a test.'\n" exit fi rm -f inbox_id.html rm -f msg_id.html rm -f sent_result.html rm -f cookies.txt if [ $INTERACTIVE ]; then echo -e "\nsend2owa $VERSION: Send Message From Linux To Outlook\n\n" read -p "Your Outlook Webmail Host Name: " OWAHOST read -p "Your Domain: " DOMAIN read -p "Your Username: " USER echo -en "Your Password: " read -rs PASS echo "" read -p "Your First Name: " FIRSTNAME read -p "Your Last Name: " LASTNAME read -p "Recipient Email Address List (Semicolon Delimited): " EMAIL_TO read -p "[OPTIONAL] CC Email Address List (Semicolon Delimited): " EMAIL_CC read -p "[OPTIONAL] BCC Email Address List (Semicolon Delimited): " EMAIL_BCC read -r -p "Email Subject: " EMAIL_SUBJECT read -r -p "Email Message: " EMAIL_MSG else OWAHOST=$1 DOMAIN=$2 USER=$3 PASS=$4 FIRSTNAME=$5 LASTNAME=$6 EMAIL_TO=$7 EMAIL_CC=$8 EMAIL_BCC=$9 EMAIL_SUBJECT=${10} EMAIL_MSG=${11} fi echo -e "\nLogging in to Outlook Webmail Server \"$OWAHOST\" ..." # LOGIN TO MAIL SERVER. NOTE FIRST TIME YOU DO THIS WE GRAB AN ERROR AND A VALID ASP SESSION COOKIE. THIS WAS THE ONLY WAY I COULD GET IN. # NEXT, IT USES THIS SESSION COOKIE ON ALL SUBSEQUENT PAGES. I HAD TO RETRIEVE logonfrm.asp TWICE BECAUSE OF I THINK MICROSOFT HAS TO TAKE # TIME ON IIS TO BUILD A SESSION OBJECT FOR US?? OH WELL -- WHATEVER WORKS curl -y 15 -c cookies.txt -u $DOMAIN\\$USER:$PASS "http://$OWAHOST/exchange/LogonFrm.asp?isnewwindow=0&mailbox=$LASTNAME%20$FI RSTNAME" > /dev/nul 2>&1 curl -y 15 -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://$OWAHOST/exchange/LogonFrm.asp?isnewwindow=0&mailbox=$LASTNAME%20$FI RSTNAME" > /dev/nul 2>&1 echo -e "Sending Message \"$EMAIL_SUBJECT\" ..." # CHEAP URLENCODING WITHOUT DOWNLOADING EXTRA TOOLS! EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/ /%20/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/?/%3F/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/\`/%60/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/~/%7E/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/!/%21/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/@/%40/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/#/%23/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/&/%26/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/*/%2A/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/(/%28/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/)/%29/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/+/%2B/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/=/%3D/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/{/%7B/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/}/%7D/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/|/%7C/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/\[/%5B/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/]/%5D/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/\\\\/%5C/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/:/%3A/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/;/%3B/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/"/%22/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed "s/'/%27/g"` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/</%3C/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/>/%3E/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/\//%2F/g'` EMAIL_SUBJECT=`echo -n $EMAIL_SUBJECT | sed 's/,/%2C/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/ /%20/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/?/%3F/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/\`/%60/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/~/%7E/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/!/%21/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/@/%40/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/#/%23/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/&/%26/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/*/%2A/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/(/%28/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/)/%29/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/+/%2B/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/=/%3D/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/{/%7B/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/}/%7D/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/|/%7C/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/\[/%5B/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/]/%5D/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/\\\\/%5C/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/:/%3A/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/;/%3B/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/"/%22/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed "s/'/%27/g"` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/</%3C/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/>/%3E/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/\//%2F/g'` EMAIL_MSG=`echo -n $EMAIL_MSG | sed 's/,/%2C/g'` # NOW WE HIT main_fr.asp TO GET A LONG INBOX ID FOR USE IN SUBSEQUENT PAGES curl -y 15 -o inbox_id.html -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://$OWAHOST/exchange/inbox/main_fr.asp?view=1&store=0&obj=&acs=" > /dev/nul 2>&1 INBOXID=$(cat inbox_id.html | grep -i "var szCurFolderID" | cut -f 4 -d " " | cut -f 2 -d "\"" | tr -d "\n") # NOW WE HIT frmroot.asp SO THAT IT ALLOCATES A FRESH MESSAGE OBJECT FOR US FOR THIS INBOX AND GIVES US A # FRESH MESSAGE OBJECT ID. curl -y 15 -o msg_id.html -b cookies.txt -u $DOMAIN\\$USER:$PASS "http://$OWAHOST/exchange/forms/ipm/note/frmroot.asp?command=new&store=0" > /dev/nul 2>&1 MSGID=$(cat msg_id.html | grep -i "+\"&obj=" | cut -f 2 -d "=" | cut -f 1 -d "\"" | tr -d "\n") # NOW WE POST OUR EMAIL FORM DATA TO /exchange/forms/ipm/note/commands.asp TO SEND THE MESSAGE OUT curl -y 15 -o sent_result.html -b cookies.txt -u $DOMAIN\\$USER:$PASS -d "to=$EMAIL_TO&cc=$EMAIL_CC&bcc=$EMAIL_BCC&subject= $EMAIL_SUBJECT&message=$EMAIL_MSG&tab=message&comm and=send&objID=$MSGID&savecopy=1&importance=1" "http://$OWAHOST/exchange/forms/ipm/note/commands.asp" > /dev/nul 2>&1 # NOW WE PLAY NICE AND FREE UP SERVER RESOURCES BY LOGGING OFF curl -y 15 -b cookies.txt -u "$DOMAIN\\$USER:$PASS" "http://$OWAHOST/exchange/logoff.asp" > /dev/nul 2>&1 if [ `cat sent_result.html | grep -i "command=holding"` ]; then echo -e "\n\tMail SENT\n\n" else echo -e "\n\tMail NOT sent!!! Try debugging send2owa script.\n\n" fi # FOR DEBUG -- COMMENT THE PAGES OUT BELOW SO THAT YOU CAN READ THE CONTENT TO DETERMINE PROBLEMS rm -f inbox_id.html rm -f msg_id.html rm -f sent_result.html rm -f cookies.txt |