Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can it be prevented from sending emails with specific file attachment (eg .txt file) in network with c#?
Posted
Comments
[no name] 3-Mar-15 1:19am    
U can put condition for selecting attachments.
Alex Sanséau 3-Mar-15 4:39am    
Are you talking about emails sent by your application only? Or any email (including those sent from Outlook or other applications)?

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900