We have an email job that uses System.Net.Mail
Emails get sent to a folder, and a job runs to copy the files to the Pickup folder on our Exchange server at a specified time of day. A copy of the email gets sent to an internal mailbox by using the Bcc field.
There is a known issue where the Bcc
property doesn't get added to emails that get sent using Exchange's Pickup folder, so the workaround is to add the Bcc field directly to the message header, however this stopped working as of 7/28/2012.
' BCC doesn't work when sent internally using the Pickup folder,
' so need to add to message headers instead
'message.Bcc.Add(New MailAddress("[email protected]"))
message.Headers.Add("Bcc", "[email protected]")
Dim smtp = New SmtpClient(exchangeServer)
smtp.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory
smtp.PickupDirectoryLocation = temporaryEmailFolder
smtp.Send(message)
Did Microsoft change something in Exchange so Bcc addresses in the email headers no longer work either? Or is there another way around this?
I tried switching to System.Web.Mail
, but I am unable to get the messages to deliver to a folder.
We're using Exchange 2010 on a Windows Server 2008 R2 Standard machine
Edit:
There were a whole bunch of updates installed on that date. I'm guessing one of them is causing this problem, but there's a huge list of them and its slow going. Anyone know of any known issues related to Bcc message headers not getting processed with the following updates?
Or does anyone know of an easier way to check out what updates do, and if these ones are causing this particular problem?
I can't figure out which update is causing this problem, and don't have the time to uninstall them one at a time to figure it out, so found an alternative.
I noticed that the header information is no longer getting added at all in the emails using my current code, but adding the address as a Bcc still creates a 2nd X-Receiver
line in the message header (which Exchange ignores when you drop the message into the Pickup folder), so I wrote a script that simply loops through the emails in the delivery folder and replaces the 2nd X-Receiver
line with a Bcc
instead.
' This no longer adds Bcc to message header for whatever reason
'message.Headers.Add("Bcc", "[email protected]")
message.Bcc.Add(New MailAddress("[email protected]"))
...
Dim content As String
Dim regex As Regex = New Regex("(X-Receiver:.*?\n)(X-Receiver:)")
' Replace of the 2nd instance of "X-Receiver:" with "Bcc:"
For Each fileName As String In Directory.GetFiles(EMAIL_DELIVERY_FOLDER)
content = File.ReadAllText(fileName)
content = regex.Replace(content, "$1Bcc:", 1)
File.WriteAllText(fileName, content)
Next
This changes the email header from
X-Sender: "Test"
<[email protected]>
X-Receiver: [email protected]
X-Receiver: [email protected]
MIME-Version: 1.0
to
X-Sender: "Test"
<[email protected]>
X-Receiver: [email protected]
Bcc: [email protected]
MIME-Version: 1.0
which correctly sends a blind copy of the email to the specified Bcc address when the .eml message is dropped into Exchange's Pickup folder