Exchange 2010 Transport Agent - Rewrite Reply-To header

744 views Asked by At

Looks like the MailItem.Message.ReplyTo property is read-only. Anyone know a way to set ReplyTo in Mailitem.Message to a new address?

Working on a Exchange 2010 Transport Agent to handle some dmarc issues with our Exchange 2010 Distribution Groups. I can change the From header and get our DG email delivered, but if could the ReplyTo header to the original email addresses, our recipients would be able to reply directly back rather than having to copy and paste the original email address I'm adding to the body of the email.

2

There are 2 answers

0
Victor Ivanidze On

Try something like this (not tested, just from my mind!):

MimeRecipient mmR = null; 
try { mmR = new MimeRecipient("John Doe", "[email protected]");} 
catch { }


Header hdrReplyTo = null;
try {hdrReplyTo = Hdrs.FindFirst(HeaderId.ReplyTo);} 
catch {}
if (null != hdrReplyTo)
{
    try 
    {
        MimeNode.Enumerator<MimeNode> enum1 = hdrReplyTo.GetEnumerator();
        try { enum1.MoveNext(); } 
        catch { }
        if (null != enum1.Current)
        { 
            try 
            {
                //delete old Reply-To               
                Hdrs.RemoveAll(HeaderId.From);
                //change From header
                hdrReplyTo.RemoveAll(); 
                hdrReplyTo.AppendChild(mmR);
                //create a new one
                Hdrs.AppendChild(hdrReplyTo); 
            } 
            catch { }
        }
    } 
    catch { }
}
0
David On

Even if this question is already more than 2 years old now, I'll post my solution (as I had the same problem myself). Maybe it helps someone that has the same problem.

MailItem.Message.ReplyTo is read-only, this is correct but only because it is a collection of the type Microsoft.Exchange.Data.Transport.Email.EmailRecipient.

You can modify a collection with remove/clear and add methods. Use this sample to remove existing Reply-To addresses and add a new one:

e.MailItem.Message.ReplyTo.Clear();
e.MailItem.Message.ReplyTo.Add("[email protected]");