First, the original intention of developing Hy.mail
There are a lot of mature and good mail repositories available on NuGet or GitHub, but the use you've found is not concise or inappropriate for my usage scenarios.
My scenario is to develop scenarios (such as system notifications, operations notifications) rather than business scenarios (sending mail to customers, HY. Mail also applies to this scenario).
Need to be able to be flexible and concise calls, need to preset some mail information.
For example, system operation: Need to do the system log mail notification, the general recipient, recipients, cc people are preselected settings. Then we need to pre-set n MailSender, and then call the corresponding MailSender as needed to send the message body, without having to set the sender's password recipient before the call.
Second, HY. Mail uses
Hy. Mail is further encapsulated with System.Net.Mail, lightweight, concise, thread-safe, optimized for multithreading.
Define your own sender (the class library is already pre-Qqmailsender):
Public classMymailsender:mailsender {Private Const stringHOST ="SMTP. Xx.com"; Private Const intPORT = -; PublicMymailsender (stringMailAddress,stringPasswordstringto="",stringCc="",stringtitle="") : Base(HOST, PORT, MailAddress, password,to,cc) {}
}
Usage:
var New Mymailsender ("[email protected]" "xxxxxxxxxxxxxxxx"); Sender.send ("[email protected] " " test mail " " message body ");
By defining sender, you can flexibly define different types of mailboxes: QQ, 163, Alibaba Mail. The default recipient can also be preset via sender, as follows:
Public Static classMymailfactory { Public Static stringTest =string. Empty; Public StaticMymailsender Toxxmailsender =NewMymailsender ("[email protected]","pwd","[email protected]"); Public StaticMymailsender Toyymailsender =NewMymailsender ("[email protected]","pwd","[email protected]"); } MyMailFactory.ToXXMailSender.Send ("title","content")
This allows for very flexible and concise invocation in different scenarios.
NuGet installation: Install-package HY. Mail
GitHub Address: Https://github.com/HYDevTools/HYMail-CSharp
Easy e-mail with C #: HY. Mail a simple, easy-to-use, flexible message tool Library