Don't accept such attachments. Yes, as simple as that. How? That question would not make much sense, as we don't know anything about your application. But this is more than apparent: if you create code sending mail, this is your who design the UI and controls where you get data for e-mail. Before the user clicks "Send" (or whatever it is), or just "Attach", the controls already have the data the user tried to enter.
The problem is pretty trivial. Please see:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachment%28v=vs.110%29.aspx[
^].
First, you can see the file "extension" and can determine if you accept it or not. But this is not just "extension". You may want to use this part of the file name to automatically determine the attachment properties or defaults for them. Ultimately, you set some
ContentType
and
ContentId
and may allow the user to directly specify one of those properties, or both. Don't include the options you don't want. Please see:
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentbase.contenttype%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/system.net.mail.attachmentbase.contentid%28v=vs.110%29.aspx[
^].
—SA