c# - Using TcpClient to connect and Send commands to smtp.gmail.com -


I am unable to send any order through smtp.gmail.com.

Let me add some mixed up characters when I connect to 465 with port number.

If I use any other port number like 25 or 587, then it fails "Hundredshed failed due to unexpected packet format."

This is my code ..

  public delegate void Sthitiapdet Avents (object o, clsStatusEventHandler e); Public Event Status Update Event Status Update; ClsStatusEventHandler objStatus = new clsStatusEventHandler (); Public Bull EnableSSL {get; Set; } Public string strIpAddress {get; Set; } Public int portNo {get; Set; } Public static string Ankodoto 64 (encoded string to) {byte [] to Ancodasbiits = Sistmtekst.assiaiaiankoding.assiaiaikgetbaits (Tunkod); String Return Values ​​= Systems Convert ToBase64String (toEncodeAsBytes); Return return value; } Public TcpClient GetTcpClient () {if (smtpTcpClient == faucet) smtpTcpClient = new TcpClient (); Return smtpTcpClient; } Public TcpClient ConnectTcpClient () {if (smtpTcpClient.Connected) smtpTcpClient.Close (); SmtpTcpClient.Connect (strIpAddress, portNo); Return smtpTcpClient; } Public Zero UpdateStatus (string strStatus) {objStatus.strStatus = strStatus; If (statusupdate! = Null) status updates (this, objStatus); } Bool certificate authentication callback (object sender, X509 Certificate, X50 9 Chen Chen, SSL Polisiirrs SSL Polisiitr) {return true; } Public Streamer GetReadStream () {If (EnableSSL == true) {smtpNetworkStream = smtpTcpClient.GetStream (); If (smtpStreamReader == faucet) {smtpStreamReader = New Streamermider (GetSslStream ()); } Return smtpStreamReader; } And {smtpNetworkStream = smtpTcpClient.GetStream (); If (smtpStreamReader == faucet) {smtpStreamReader = New StreamReader (smtpNetworkStream); } Return smtpStreamReader; }} Public Streamer GetWriteStream () {if (EnableSSL == true) {smtpNetworkStream = smtpTcpClient.GetStream (); // readerSmtp = new Strymrider (New System.Net.Security.SslStream (clientSmtp.GetStream (), true, certificate ValidationCallback)); If (smtpStreamWriter == zero) {smtpStreamWriter = new streamer (GetSslStream ()); } Return smtpStreamWriter; } And {smtpNetworkStream = smtpTcpClient.GetStream (); If (smtpStreamWriter == zero) {smtpStreamWriter = new streamer (smtpNetworkStream); } Return smtpStreamWriter; }} SSL Stream GetSslStream () {if (SSL = Stream == blank) {sslstream = new SSL stream (smtpNetworkStream); Sslstream.AuthenticateAsClient (strIpAddress, Empty, System.Security.Authentication.SslProtocols.Tls, False); } Return sslstream; } Public Zero DoConnect (string strIpAddress, int portno, bool EnableSSL) {this.strIpAddress = strIpAddress; This.portNo = portno; {Trying to connect to "UpdateStatus" ("String Aid + +": "+ portno.ToString ()); SmtpTcpClient = GetTcpClient (); SmtpTcpClient.Connect (strIpAddress, portno); If (EnableSSL == true) {this.EnableSSL = EnableSSL; SmtpNetworkStream = smtpTcpClient.GetStream (); //sslstream.Write (system.assic.assicIIEncoding.ASCII.GetBytes ("ELLO some 123@gmail.com \ n")); //sslstreamkWrite (System. Text. ASCIIEncoding.ASCII.GetBytes (/ STSTTLS \ n ")); SmtpStreamReader = GetReadStream (); // New Stream Reader (New System.Net.Security.SslStream (smtpTcpClient.GetStream () is true, certificates ValidationCallback)); // readerSmtp = new Strymrider (Sselstrym);} other {EnableSSL = false; SmtpNetworkStream = smtpTcpClient.GetStream (); SmtpStreamReader = GetReadStream ();} Apdetstats (Reedspens ());} catch (exception e) {//MessageBox.Show.e.Message); Apdetstats ( "**** connection error ****" + "\ n" + e. message); smtpTcpClient.Close ();}} < / Code>  

Please help me .. Thank you very much ago ..

Edit Do I know about System.net.mail.smtpclient and I Opensource smtp library available. But, I can not use it to send manually smtp command it to send e-mail. This SSL Step through to see the e-mail protocol phase.

you may just Use it as it has been used with

Comments