简体   繁体   中英

Sending Email through C# winform application

I have three problems in C# WinForm application sending email.

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?

2) When testing this my antivirus (quick heal) installed on my PC is blocking my application and saying that is not trusted email client. How can I include my application in antivirus / windows trusted email client list programmatically?

3) Is it required that we should use default port 25 or any other port like 465 or 587?

The class SmtpClient in the namespace System.Net.Mail contains properties for Host and 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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