views:

36

answers:

1

I've written an automated e-mailer for my company's invoices. Things are all fine and dandy till I ran across a couple emails that weren't getting delivered.

Upon further inspection our IT Guru found that the messages sent by the emailer have incorrect MessageID headers.

Message-ID: <98bcd4e6-be30-4b22-8026-6047c8231b1f>

Where they should look something like this:

Message-ID: <F09A215A213060419E28A88E85FDC8FD0CCEB91C23@EXCHANGE-SERVER.MYDOMAIN.mycompany.com>

I've looked around the internet for 'invalid message-id' related to .NET's SqlClient with no success. This is prettymuch the last lynch-pin in this whole system, hopefully there's an answer out there.

Code:

MailMessage message = new MailMessage();

foreach(string recipient in msgRecipients)
{
    message.To.Add(new MailAddress(recipient));
}

message.From = new MailAddress(InvoiceEmailerConfig.Section.EmailCourier.FromEmail);
message.ReplyTo = new MailAddress(InvoiceEmailerConfig.Section.EmailCourier.ReplyToEmail);
message.Subject = messageHeading;
message.Body = msgBody;

SmtpClient mailer = new SmtpClient(SmtpServer, SmtpServerPort);
mailer.DeliveryMethod = SmtpDeliveryMethod.Network;
mailer.Credentials = new NetworkCredential(SmtpLogin, SmtpPassword);
mailer.Send(message);
+2  A: 

I had similar problem on RHEL server, turned out my Sendmail was not configured properly. I think you should check Exchange settings.

You can also set the Message ID explicitly, exchange will use that Message-ID to send an email.

MailMessage message = new MailMessage();
message.Headers.Add("Message-ID", "MyMessageID");
Alex
Do you know if there's any stipulation on the message ID field? Does it have to reference something in the exchange server or can i just generate something random @mydomain.com ?
Aren
I set the headers manually for an email portal in one of our products which helps me reconcile replies. You can set the message-id header manually to a valid message-id as shown by Alex and it should work just fine.
Wil P
@Wil P: So you just generated a random HEX Code of appropriate length?
Aren
I follow RFC2822.
Wil P
After a very extensive search, It seems that your approach is both valid and works. The problem is that there's a bug in our exchange server's version that's setting a bad message-id for messages that do not contain one. So simply setting a valid one fixed my problems.
Aren