0

Exchange deletes Non-Delivery-Reports (NDRs) if the target is a public folder.

I want to write a Transport Agent (SMTPReceiveAgent, c#) to bypass this behavior. The goal is to change the NDR to a "normal" mail, that dont delete by exchange. I test some thinks around this and found no solution. Now i need help.

Here some questions:

  1. It's easy to identify an NDR.

    Content-Type: multipart/report; report-type=delivery-status;

    But what i have to change at the mail to convert this to a "normal" mail? Change to multipart/alternative not work or is not enough.

  2. As an alternative i can create a new message with all infos captured from the NDR. What is the best way to do this inside a SMTReceiveAgents.OnSubmitted Event?

  3. To create a copy from the public folder NDR for a normal user i tried args.Mailitem.Recipients.Add(new RoutingAddress("username@mydomain.com")) in the EndOfDataHandler. This doesnt work. Why?

Any answers, hints or solutions?

quantum
  • 3,672
  • 29
  • 51

1 Answers1

0

Exchange 2007 NDRs to public Folders

Q1. You do have to change it to multipart/alternative, but also, you should find "Content-Type: message/delivery-status" and change it to text/plain but it isnt required

Q2. You could do this but your only options for the "original" message is to reject it to the sender, quarantine it or allow it..there is no delete / drop option.. but since it's going to a public folder it would be discarded.

If you go this route then enumerate the headers and body during EndOfHeadersEvent and then generate a new MailMessage object and include the headers and body from the original

Q3. That should work.. only reason that I can see it wouldnt work is if you're trying to send to an external recipient / domain that isn't an accepted domain on the server..if that is what youre trying to do then you'll need to create a mail contact with your real external address and then CC the NDR to the external contact

Below is the code I was able to accomplish what you're trying to do. The reason I hook into onRcpt and onEndOfHeaders is to check if the recipient entered is the public folder address..I found it faster than enumerating the rcpt list at the end of the header

NDR Saved to Public Folder

void UserSendCounterSmtpReceiveAgent_OnRcptCommand(ReceiveCommandEventSource source, RcptCommandEventArgs e)
        {
            if(source == null || e == null)
            {
                return;
            }
            String recipient = e.RecipientAddress.ToString();
            if (recipient.Equals("publicfolder@domain.com"))
            {
                this.testOnEndOfHeaders = true;
            }

        }
        void UserSendCounterAgent_OnEndOfHeaders(ReceiveMessageEventSource source, EndOfHeadersEventArgs e)
        {
            if (source == null || e == null)
            {
                return;
            }

                if (testOnEndOfHeaders)
                {
                    this.testOnEndOfHeaders = false;
                    Header obj = e.Headers.FindFirst("Content-Type");
                    if (obj.Value.Equals(@"multipart/report"))
                    {
                        obj.Value = @"multipart/alternative";
                        e.MailItem.Recipients.Add(new RoutingAddress("forwardto@domain.com"));
                    }

                }

        }
Community
  • 1
  • 1
ainesophaur
  • 774
  • 5
  • 12