I wonder if MailMessage class is protected from e-mail injection. For example, should I check values before passing them to its constructor:
MailMessage message = new MailMessage(fromTextBox.Text, toTextBox.Text);
I wonder if MailMessage class is protected from e-mail injection. For example, should I check values before passing them to its constructor:
MailMessage message = new MailMessage(fromTextBox.Text, toTextBox.Text);
There seems to be only a simple check in the MailAddress class which checks if the address contains an @.
I took a quick look at the source code and it seems there is no checks at all (except those that the params are not null) But if you simply create a MailMessage, there should be no problem at all, because its plain text... Only when using Alternate Views you should be aware of injections.
The MailAddress
class checks its addresses against the full BNF grammar from RFC822. (See MailBnfHelper
).
There is no risk of injection when using MailMessage
s. (Except HTML injection in your own content)