C#SMTP Multithreading

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.IO;usingSystem.Linq;usingSystem.Net.Mail;usingSystem.Net.Sockets;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading;usingSystem.Windows.Forms;namespaceSMTP Test { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        BOOLb =false; Private voidForm1_Load (Objectsender, EventArgs e) {        }        Private voidButton1_Click (Objectsender, EventArgs e) {             for(inti =0; I <5; i++) {Thread th=NewThread (NewThreadStart (Delegate{Console.WriteLine (CHECKSMTP ("smtp.126.com", -,"User","pswd"));                                                           })); Th. IsBackground=true; Th.            Start (); }        }        Private BOOLCHECKSMTP (stringSmtpServer,intPortstringUsernamestringpassword) {TcpClient TcpClient=NewTcpClient (SmtpServer, Port); NetworkStream Stream=Tcpclient.getstream (); if(! Waitefor (Stream," -"))return false; SendCommand (Stream,"HELO 211.152.50.xxx\r\n"); if(! Waitefor (Stream," -"))return false; SendCommand (Stream,"AUTH login\r\n"); if(! Waitefor (Stream,"334"))return false; SendCommand (Stream, Base64Encode (username)+"\ r \ n"); if(! Waitefor (Stream,"334"))return false; SendCommand (Stream, Base64Encode (password)+"\ r \ n"); if(! Waitefor (Stream,"235"))return false; return true; }        Private BOOLWaitefor (NetworkStream Stream,stringstrcode) {            intstreamsize; byte[] Readbuffer =New byte[1024x768]; Streamsize= Stream. Read (Readbuffer,0, readbuffer.length); stringreturnvalue = Encoding.Default.GetString (Readbuffer). Substring (0, streamsize); //Console.WriteLine (returnvalue);            returnReturnvalue.substring (0,3).        Equals (Strcode); }        Private voidSendCommand (NetworkStream Stream,stringstrcmd) {            byte[] writebuffer; WriteBuffer=Encoding.Default.GetBytes (Strcmd); Stream. Write (WriteBuffer,0, writebuffer.length); }        Private stringBase64Encode (stringstr) {            byte[] barray; Barray=Encoding.Default.GetBytes (str); returnconvert.tobase64string (Barray); }             }}

C#SMTP Multithreading

Related Article

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.