Rewrite the "[original] EMAIL sending system (C # + based on SMTP authentication )"

Source: Internet
Author: User

When I wrote a notification service for the company, I found the above address online. I am very grateful to the original author for his creative work. The purpose of rewriting is to meet the requirements of running as a service:
1. To meet the requirements of multithreading, the mail sending service can run in the background, and the connection with the SMTP server is considered as an exclusive resource.
2. To meet the stability requirements, do not simply throw an exception to handle the error. After an exception occurs, wait for a certain period of time before trying again. If the exception persists after a period of time, it is considered as an SMTP error and the identity of the failed email sending is returned.
3. Simplified attributes and Methods. Mail-related information is not passed in as an attribute but as a send parameter. Only a non-overloaded send method is published. This class is used as the base class, and the interface method required by the notification service is written in another way.
The following code is rewritten:
Using System;
Using System. Text;
Using System. IO;
Using System. Net;
Using System. Net. Sockets;
Using System. Collections;
Using System. Threading;
Namespace Deep. SendEmail
{
# Region AspNetPager Server Control
/// <Summary>
/// Mail can be transmitted through the built-in SMTP mail service in Microsoft Windows 2000 or any SMTP Server
/// </Summary>
Public class SmtpMail
{
Private const string ENTER = "";
/// <Summary>
/// Set the language code. The default value is GB2312. You can set it to "" if not required ""
/// </Summary>
Private string m_charset = "GB2312 ";

/// <Summary>
/// Server interaction record
/// </Summary>
Private StringBuilder m_logs = new StringBuilder ();
Private string m_ErrCode;
/// <Summary>
/// SMTP error code hash table
/// </Summary>
Private Hashtable m_ErrCodeHT = new Hashtable ();
/// <Summary>
/// SMTP hash table with correct code
/// </Summary>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.