Advertisement
Guest User

Untitled

a guest
Sep 27th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.12 KB | None | 0 0
  1. private void BtnConnect_Click(object sender, EventArgs e)
  2.         {
  3.             string cm_status = "notstarted";
  4.             bool success = false;
  5.  
  6.             if (CbType.Text == "IMAP")
  7.             {
  8.                 using (Chilkat.Imap imap = new Chilkat.Imap())
  9.                 {
  10.                     success = imap.UnlockComponent("Anything for 30-day trial");
  11.                     if (success == true)
  12.                     {
  13.                         imap.KeepSessionLog = true;
  14.                         imap.ConnectTimeout = 30;
  15.                         imap.ReadTimeout = 30;
  16.  
  17.                         imap.Port = Convert.ToInt32(NudPort.Value);
  18.                         imap.Ssl = Convert.ToBoolean(CbSSL.Text);
  19.  
  20.                         success = imap.Connect(TbServer.Text);
  21.                         if (success == true)
  22.                         {
  23.                             success = imap.Login(TbMail.Text, TbPassword.Text);
  24.                             if (success == true)
  25.                             {
  26.                                 cm_status = "good_mail";
  27.                             }
  28.                             else
  29.                             {
  30.                                 if (TbServer.Text == "imap.gmail.com")
  31.                                 {
  32.                                     if (imap.SessionLog.Contains("Please log in via your web browser") || imap.SessionLog.Contains("Application-specific password required"))
  33.                                     {
  34.                                         cm_status = "blocked_mail";
  35.                                     }
  36.                                     else
  37.                                     {
  38.                                         cm_status = "bad_mail";
  39.                                     }
  40.                                 }
  41.                                 else if (TbServer.Text == "imap.mail.ru")
  42.                                 {
  43.                                     if (imap.SessionLog.Contains("Please verify your account"))
  44.                                     {
  45.                                         cm_status = "blocked_mail";
  46.                                     }
  47.                                     else
  48.                                     {
  49.                                         cm_status = "bad_mail";
  50.                                     }
  51.                                 }
  52.                                 else
  53.                                 {
  54.                                     cm_status = "bad_mail";
  55.                                 }
  56.                             }
  57.                             imap.Disconnect();
  58.                         }
  59.                         else
  60.                         {
  61.                             if (imap.LastErrorText.Contains("Failed to connect"))
  62.                             {
  63.                                 cm_status = "bad_proxy";
  64.                             }
  65.                             else
  66.                             {
  67.                                 cm_status = "error";
  68.                             }
  69.                         }
  70.                         Console.WriteLine(imap.SessionLog);
  71.                     }
  72.                     else
  73.                     {
  74.                         cm_status = "error";
  75.                     }
  76.                     Console.WriteLine(imap.LastErrorText);
  77.                 }
  78.             }
  79.             else if (CbType.Text == "POP3")
  80.             {
  81.                 using (Chilkat.MailMan pop3 = new Chilkat.MailMan())
  82.                 {
  83.                     success = pop3.UnlockComponent("Anything for 30-day trial");
  84.                     if (success == true)
  85.                     {
  86.                         pop3.ConnectTimeout = 30;
  87.                         pop3.ReadTimeout = 30;
  88.  
  89.                         pop3.MailHost = TbServer.Text;
  90.                         pop3.MailPort = Convert.ToInt32(NudPort.Value);
  91.                         pop3.PopSsl = Convert.ToBoolean(CbSSL.Text);
  92.  
  93.                         pop3.PopUsername = TbMail.Text;
  94.                         pop3.PopPassword = TbPassword.Text;
  95.  
  96.                         success = pop3.Pop3Connect();
  97.                         if (success == true)
  98.                         {
  99.                             success = pop3.Pop3Authenticate();
  100.                             if (success == true)
  101.                             {
  102.                                 cm_status = "good_mail";
  103.                             }
  104.                             else
  105.                             {
  106.                                 if (TbServer.Text == "pop.gmail.com")
  107.                                 {
  108.                                     if (pop3.Pop3SessionLog.Contains("Web login required") || pop3.Pop3SessionLog.Contains("Application-specific password required"))
  109.                                     {
  110.                                         cm_status = "blocked_mail";
  111.                                     }
  112.                                     else
  113.                                     {
  114.                                         cm_status = "bad_mail";
  115.                                     }
  116.                                 }
  117.                                 else
  118.                                 {
  119.                                     cm_status = "bad_mail";
  120.                                 }
  121.                             }
  122.                             pop3.Pop3EndSession();
  123.                         }
  124.                         else
  125.                         {
  126.                             if (pop3.LastErrorText.Contains("Failed to connect"))
  127.                             {
  128.                                 cm_status = "bad_proxy";
  129.                             }
  130.                             else
  131.                             {
  132.                                 cm_status = "error";
  133.                             }
  134.                         }
  135.                         Console.WriteLine(pop3.Pop3SessionLog);
  136.                     }
  137.                     else
  138.                     {
  139.                         cm_status = "error";
  140.                     }
  141.                     Console.WriteLine(pop3.LastErrorText);
  142.                 }
  143.             }
  144.             Console.WriteLine(cm_status);
  145.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement