14 April 2012 0:31
We had a working ASP.NET application sending mail through our old Exchange 2003 server using the pickup directory method. We recently migrated to Windows Server 2008 R2 with Exchange 2010, and now email sent using the pickup directory method is being corrupted with extra periods being placed in URLs eg:
I believe this has something to do with how SMTP handles periods if they fall at the beginning of lines.
If I use the Network method to send the mail from the application this probem disappears. It only happens using the pickup directory method and only since upgrading to Exchange 2010. Here is my code:
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
// Set the Bcc address of the mail message
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
// Set the CC address of the mail message
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body;
// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
If I use this class from a test snippet as follows (the body is just to make double periods easy to spot):
string FromEmail = "firstname.lastname@example.org";
string ToEmail = "email@example.com";
string Subject = "SMTP Test";
string CC = "";
string BCC = "";
string EmailBody = "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0";
MailHelper.SendMailMessage(FromEmail, ToEmail, BCC, CC, Subject, EmailBody);ect, EmailBody);
The email then looks like this:
Note the double period.
21 April 2012 19:16No one have any ideas on this one ?
22 April 2012 9:44
The Pickup directory is a pain to work with and what you're seeing is a know issue.
Specifically you're probably seeing this ...
1. Before sending a line of mail text the sender-SMTP checks the first character of the line. If it is a period, one additional period is inserted at the beginning of the line.
There are workarounds (see the KB) but I'd recommend using the Replay directory instead as it avoids this problem and gives you more control:
- The envelope recipients can differ from the message recipients.
- You have more control over the delivery status notifications (DSNs).
- And (importantly for you) Exchange only parses the 1st few lines of x-headers when it picks up the message.
This should get you started:
Scott Quinn | C# developer & messaging specialist (for hire). Contact me at http://au.linkedin.com/in/scottquinn
26 April 2012 23:11
Many thanks - I'll check it out
09 Mei 2012 21:40I have tried using the Replay directory with exactly the same result - periods are still being added to the body of the email.
10 Mei 2012 22:23
Finally found the fix - force base64 encoding using :
MailMessage.BodyEncoding = System.Text.Encoding.UTF8;