?
Solved

Messages not being routed when using WebDAV to send email

Posted on 2008-09-30
8
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
To show how to generate a certificate request 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 Servers >> Certificates…
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, fr…
Suggested Courses

800 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