Solved

Messages not being routed when using WebDAV to send email

Posted on 2008-09-30
8
410 Views
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  'somedomain.com' 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?
0
Comment
Question by:Doromir
  • 5
  • 3
8 Comments
 
LVL 31

Expert Comment

by:LeeDerbyshire
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)?
0
 

Author Comment

by:Doromir
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();
            ma.Add(mail.From);
            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;");
            else
                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");
            mailHeader.Append("\r\n");
 
            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)
                Session.Authenticate();
            Stream strm = null;
            HttpWebRequest HttpWRequest;
            HttpWebResponse HttpWResponse;
            Stream QueryStream;
            StreamReader sr;
 
            try
            {
                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);
                QueryStream.Close();
 
                // 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();
            }
            catch
            {
                throw;
            }
            finally
            {
                // Close the stream.
                if (strm != null)
                    strm.Close();
                HttpWRequest = null;
                HttpWResponse = null;
                QueryStream = null;
                strm = null;
                sr = null;
            }
        }

Open in new window

0
 

Author Comment

by:Doromir
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Accepted Solution

by:
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.
0
 

Author Comment

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

Expert Comment

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

Author Closing Comment

by:Doromir
ID: 31501627
Thanks!
0
 

Author Comment

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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

733 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