?
Solved

Messages not being routed when using WebDAV to send email

Posted on 2008-09-30
8
Medium Priority
?
416 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
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 31

Accepted Solution

by:
LeeDerbyshire earned 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Suggested Courses
Course of the Month17 days, 2 hours left to enroll

862 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