Messages not being routed when using WebDAV to send email

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?
DoromirAsked:
Who is Participating?
 
LeeDerbyshireConnect With a Mentor Commented:
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
 
LeeDerbyshireCommented:
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
 
DoromirAuthor Commented:
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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
DoromirAuthor Commented:
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
 
DoromirAuthor Commented:
I will try it your way and return. Thanks
0
 
LeeDerbyshireCommented:
Okay, and I should have been more specific - try using PROPPATCH, rather than PUT.
0
 
DoromirAuthor Commented:
Thanks!
0
 
DoromirAuthor Commented:
Yes. Creating the mail in the Draft-folder and then use MOVE did the trick. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.