简体   繁体   English

通过C#winform应用程序发送电子邮件

[英]Sending Email through C# winform application

I have three problems in C# WinForm application sending email. 我在C#WinForm应用程序发送电子邮件中遇到三个问题。

1) For sending email, I have to choose the host and port number at runtime eg smtp.mail.yahoo.com and port number 465 or smtp.google.com and port number 587. What's the best way to accomplish this? 1)要发送电子邮件,我必须在运行时选择主机和端口号,例如smtp.mail.yahoo.com和端口号465或smtp.google.com和端口号587。完成此操作的最佳方法是什么?

2) When testing this my antivirus (quick heal) installed on my PC is blocking my application and saying that is not trusted email client. 2)测试时,我安装在PC上的防病毒软件(快速修复)阻止了我的应用程序,并说这不是受信任的电子邮件客户端。 How can I include my application in antivirus / windows trusted email client list programmatically? 如何以编程方式将我的应用程序包含在防病毒/ Windows受信任的电子邮件客户端列表中?

3) Is it required that we should use default port 25 or any other port like 465 or 587? 3)是否要求我们使用默认端口25或其他任何端口(例如465或587)?

The class SmtpClient in the namespace System.Net.Mail contains properties for Host and Port. 名称空间System.Net.Mail中的SmtpClient类包含Host和Port的属性。
So there is no problem in setting different ports and hosts. 因此,设置不同的端口和主机没有问题。 The real port on which you will send your mail depends on the Smtp Service you choose to use. 您将在其上发送邮件的实际端口取决于您选择使用的Smtp服务。

For the best place how to store the host and port configuration. 最好的地方,如何存储主机和端口配置。
It depends on the purpose. 这取决于目的。 Use .config file (application settings) if this is one time configuration needed only during setup process and fixed for all your users. 如果仅是在安装过程中需要一次配置,并且对所有用户都是固定的,请使用.config文件(应用程序设置)。 Use config file (user settings) if you want give to each of your users the functionality to change this data during runtime. 如果要向每个用户提供在运行时更改此数据的功能,请使用配置文件(用户设置)。 Also if your application has a database you can consider an Options table with info on configuration. 同样,如果您的应用程序具有数据库,则可以考虑带有配置信息的“选项”表。

For the 'programmatically add my application to antivirus'. 对于“以编程方式将我的应用程序添加到防病毒程序”。
I think it's very difficult if possible at all. 我认为这是非常困难的。 Security will be severely undermined. 安全将受到严重破坏。
And, in the end, every solution, will depends on a particular API for a particular Antivirus vendor. 最后,每种解决方案都将取决于特定防病毒供应商的特定API。

  1. Depends on where/how/what you pull this port data from. 取决于从何处/如何/从何处提取此端口数据。 Where are you getting the number from? 您从哪里得到电话号码?

  2. Well that doesn't matter does it because according to number 1 this will be chosen at runtime!? 好吧,这无关紧要,因为将根据数字1在运行时选择它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM