阻止在c#中发送带有特定文件附件的电子邮件 [英] prevented from sending e-mails with specific file attachment in c#

查看:98
本文介绍了阻止在c#中发送带有特定文件附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止使用c#在网络中发送带有特定文件附件(例如.txt文件)的电子邮件?

How can it be prevented from sending emails with specific file attachment (eg .txt file) in network with c#?

推荐答案

不接受此类附件。是的,就这么简单。怎么样?这个问题没有多大意义,因为我们对您的申请一无所知。但这显而易见:如果您创建代码发送邮件,那么您可以设计UI并控制您获取电子邮件数据的位置。在用户点击发送(或其他任何内容)或仅附加之前,控件已经拥有用户试图输入的数据。



问题是非常微不足道的。请参阅:

https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage%28v=vs.110%29.aspx [ ^ ],

https:// msdn .microsoft.com / zh-CN / library / system.net.mail.attachment%28v = vs.110%29.aspx [ ^ ]。



首先,您可以看到文件扩展名,并可以确定您是否接受它。但这不仅仅是扩展。您可能希望使用文件名的这一部分来自动确定附件属性或默认值。最后,您设置了一些 ContentType ContentId ,并且可以允许用户直接指定其中一个属性,或两者都指定。不要包含您不想要的选项。请参阅:

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
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


这篇关于阻止在c#中发送带有特定文件附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆