Why does changing the sender/from in an Exchange Transport Agent result in the primary address of that user?

200 views Asked by At

I've successfully created an SmtpReceiveAgent with OnEndOfDataEvent. It should replace the sender of some emails, so the recipient sees the new sender and is able to reply to it.

This already works very well, just by setting:

MailItem.Message.From = new EmailRecipient(DisplayName, Address);

It doesn't seem to be necessary to also set the following places, like in many examples I found:

MailItem.Message.Sender = new EmailRecipient(DisplayName, Address);
MailItem.FromAddress = new RoutingAddress(Address);

I am able to set any random non-existing or external address, or any existing address of other users in the same company/domain.

However, when that user exists in our system, and it is not its primary address, it is replaced by the primary address. But that's exactly what I wanted: use alternative addresses... How to fix this?

1

There are 1 answers

0
maf-soft On BEST ANSWER

No idea why this happened, but when I replaced
SmtpReceiveAgent and OnEndOfDataEvent by
RoutingAgent and OnCategorizedMessage,
it just started to work without other changes.

I also added setting MailItem.FromAddress now,
so the Return-Path header was affected correctly.