There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
EmailMessageEventHandler should respect MessagePrepared flag.
Let's say I create my own IMessageEventHandler implementation as part of a feature that sends my own message type using my own channel. This handler adds recipients (passed through via MessageContext.Address) to the MailMessage.To collection.
However, if Orchard.Email is enabled, its EmailMessageEventHandler will ALSO add MessageContext.Address to the MailMessage.To collection.
So if both Orchard.Email and my custom feature are enabled, a recipient address gets added twice to the MailMessage.To collection.
To correct this, the EmailMessageEventHandler should check for the MessagePrepared flag of the context, and exit early if set to true.
This will have ramifications though: the MailActions.cs file has a MailActionsHandler class that implements IMessageEventHandler, but it relies on EmailMessageEventHandler to actually add MessageContext.Address to the MailMessage.To list. Since this handler
sets the MessagePrepared to true, after implementing my suggested change, nobody will receive any email (which does not necessarily have to be a bad thing ;)).
To complete the fix, this MailActionsHandler needs to add the addresses itself to the To collection.
I can see how the two classes were designed to work together, but for the scenario just described, it does not work well, so I would like to suggest refactoring this a bit as described.