Messages not being routed when using WebDAV to send email

Posted on 2008-09-30
Last Modified: 2013-12-06
Server 2003 Standard Edition
Exchange 2003

I use WebDAV to send e-mails (receipt from webshop for example) to users.
The sent messages are ALMOST always being rejected by the remote server, eg:
Message delivery to the host 'xx.xx.xx.xx' failed while delivering to the remote domain  '' for the following reason: The connection was dropped by the remote host.

When I forward the same message to the same adress using OWA, the message is being delivered.
I have tested to send to my own gMail account, and it works most of the times, but sometimes the same message can be rejected.

The message appears in "sent"-folder and appears in the Exchange queue.

I use a smarthost normally, but have tried to switch to DNS, with no luck.
Any ideas?
Question by:Doromir
  • 5
  • 3
LVL 31

Expert Comment

ID: 22613610
Hard to say without seeing the code.  Since the messages are sometimes delivered, then you are probably doing it correctly, in a technical sense, but you may be getting caught by a spam blocker.  Is the remote receiving server (is it always the same one) part of your own LAN or domain (so that you can check its configuration)?

Author Comment

ID: 22613676
Hi LeeDerbyshire!
Thanks for your input.
Yes, I suspect that SPAM-blockers of some kind are causing trouble. The strange thing is that using OWA is no problem.

I have seen in the message header that an extra line is added in the "Hop"-history. Can that extra line be causing the trouble? Is there any way to remove it?

It also seems as if it is the HTML-messages that are affected the most. Plain text seems to be routed OK.
I attach the code for contructing the mail header and sending the message.
        private string GetMailHeader(Mail mail)


            StringBuilder mailHeader = new StringBuilder();

            System.Net.Mail.MailAddressCollection ma = new System.Net.Mail.MailAddressCollection();


            mailHeader.Append(mail.GetRecipientField(ma, "From"));

            mailHeader.Append(mail.GetRecipientField(mail.To, "To"));

            mailHeader.Append(mail.GetRecipientField(mail.CC, "Cc"));

            mailHeader.Append(mail.GetRecipientField(mail.Bcc, "Bcc"));

            mailHeader.AppendFormat("Subject: {0}\r\n", mail.Subject);

            mailHeader.AppendFormat("Date: {0}\r\n", DateTime.Now.ToString());

            mailHeader.AppendFormat("X-Mailer: {0}\r\n", "HCE 2");

            mailHeader.AppendFormat("MIME-Version: {0}\r\n", "1.0");

            if (mail.IsBodyHtml)

                mailHeader.AppendFormat("Content-Type: {0} ", "text/html;");


                mailHeader.AppendFormat("Content-Type: {0} ", "text/plain;");

            mailHeader.AppendFormat("charset={0}\r\n", "\"ISO-8859-1\"");

            mailHeader.AppendFormat("Content-Transfer-Encoding: {0}\r\n", "7bit");


            return mailHeader.ToString();


        public void SendMail(Mail mail)


            string path;

            path = "/Exchange/" + Session.Alias;

            path = path + "/%23%23DavMailSubmissionURI%23%23/";

            StringBuilder mailHeader = new StringBuilder(GetMailHeader(mail));

            mailHeader.AppendFormat("{0}", mail.Body);

            WebMethods wb = new WebMethods(Session);

            wb.ExecutePutMethod(path, mailHeader.ToString(), "message/rfc822");


        internal string ExecutePutMethod(string path, string query, string contentType, System.Text.Encoding encoding)


            if (Session.CurrentExchangeSessionState != ExchangeSessionState.ConnectionOpen)


            Stream strm = null;

            HttpWebRequest HttpWRequest;

            HttpWebResponse HttpWResponse;

            Stream QueryStream;

            StreamReader sr;



                System.Uri myUri = new System.Uri(Session.ServerURLAndProtocol + path);

                HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);

                HttpWRequest.CookieContainer = Session.AuthenticationCookies;

                HttpWRequest.ContentType = contentType;

                HttpWRequest.ContentLength = query.Length;

                HttpWRequest.Timeout = 300000;

                // Set the request method.

                HttpWRequest.Method = "PUT";

                // Store the data in a byte array.

                byte[] ByteQuery = encoding.GetBytes(query);

                HttpWRequest.ContentLength = ByteQuery.Length;

                QueryStream = HttpWRequest.GetRequestStream();

                // write the data to be posted to the Request Stream

                QueryStream.Write(ByteQuery, 0, ByteQuery.Length);


                // Send the request and get the response.

                HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();

                // Get the Status code.

                int iStatCode = (int)HttpWResponse.StatusCode;

                string sStatus = iStatCode.ToString();

                // Get the request headers.

                string sReqHeaders = HttpWRequest.Headers.ToString();

                // Read the response stream.

                strm = HttpWResponse.GetResponseStream();

                sr = new StreamReader(strm);

                return sr.ReadToEnd();








                // Close the stream.

                if (strm != null)


                HttpWRequest = null;

                HttpWResponse = null;

                QueryStream = null;

                strm = null;

                sr = null;



Open in new window


Author Comment

ID: 22613707
Extra comment on above. When I add the HTML-body I just add it below the header as if it was plain text. Exchange seems to format everythong OK, it even adds a plain text part to the message.
LVL 31

Accepted Solution

LeeDerbyshire earned 500 total points
ID: 22613737
I've never done it that way, but I suspect that if you are constructing your own headers, and then using PUT to generate the message, then some receiving servers may spot something that they think is suspicious.

Is there any chance you could modify the code to create the message in the Drafts folder, and then MOVE it to the submission URL?  This is the way OWA would so it, and my guess is that this would create better headers, and account for the fact that its delivery rate is better.
The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.


Author Comment

ID: 22613788
I will try it your way and return. Thanks
LVL 31

Expert Comment

ID: 22613851
Okay, and I should have been more specific - try using PROPPATCH, rather than PUT.

Author Closing Comment

ID: 31501627

Author Comment

ID: 22632958
Yes. Creating the mail in the Draft-folder and then use MOVE did the trick. Thanks!

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now