<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FNetwork%2FMail</id>
		<title>Csharp/C Sharp/Network/Mail - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FNetwork%2FMail"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Network/Mail&amp;action=history"/>
		<updated>2026-04-29T17:58:42Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Network/Mail&amp;diff=1489&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Network/Mail&amp;diff=1489&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:19Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Network/Mail&amp;diff=1490&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Network/Mail&amp;diff=1490&amp;oldid=prev"/>
				<updated>2010-05-26T11:47:09Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A POP3 e-mail checker==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Network Programming &lt;br /&gt;
by Richard Blum&lt;br /&gt;
Publisher: Sybex &lt;br /&gt;
ISBN: 0782141765&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
public class PopCheck : Form&lt;br /&gt;
{&lt;br /&gt;
   private TextBox hostname;&lt;br /&gt;
   private TextBox username;&lt;br /&gt;
   private TextBox password;&lt;br /&gt;
   private TextBox status;&lt;br /&gt;
   private ListBox messages;&lt;br /&gt;
   private TcpClient mailclient;&lt;br /&gt;
   private NetworkStream ns;&lt;br /&gt;
   private StreamReader sr;&lt;br /&gt;
   private StreamWriter sw;&lt;br /&gt;
   public PopCheck()&lt;br /&gt;
   {&lt;br /&gt;
      Text = &amp;quot;popcheck - A POP3 e-mail checker&amp;quot;;&lt;br /&gt;
      Size = new Size(400, 380);&lt;br /&gt;
      Label label1 = new Label();&lt;br /&gt;
      label1.Parent = this;&lt;br /&gt;
      label1.Text = &amp;quot;Hostname:&amp;quot;;&lt;br /&gt;
      label1.AutoSize = true;&lt;br /&gt;
      label1.Location = new Point(10, 33);&lt;br /&gt;
      hostname = new TextBox();&lt;br /&gt;
      hostname.Parent = this;&lt;br /&gt;
      hostname.Size = new Size(200, 2 * Font.Height);&lt;br /&gt;
      hostname.Location = new Point(75, 30);&lt;br /&gt;
      Label label2 = new Label();&lt;br /&gt;
      label2.Parent = this;&lt;br /&gt;
      label2.Text = &amp;quot;User name:&amp;quot;;&lt;br /&gt;
      label2.AutoSize = true;&lt;br /&gt;
      label2.Location = new Point(10, 53);&lt;br /&gt;
      username = new TextBox();&lt;br /&gt;
      username.Parent = this;&lt;br /&gt;
      username.Size = new Size(200, 2 * Font.Height);&lt;br /&gt;
      username.Location = new Point(75, 50);&lt;br /&gt;
      Label label3 = new Label();&lt;br /&gt;
      label3.Parent = this;&lt;br /&gt;
      label3.Text = &amp;quot;Password:&amp;quot;;&lt;br /&gt;
      label3.AutoSize = true;&lt;br /&gt;
      label3.Location = new Point(10, 73);&lt;br /&gt;
      password = new TextBox();&lt;br /&gt;
      password.Parent = this;&lt;br /&gt;
      password.PasswordChar = &amp;quot;*&amp;quot;;&lt;br /&gt;
      password.Size = new Size(200, 2 * Font.Height);&lt;br /&gt;
      password.Location = new Point(75, 70);&lt;br /&gt;
      Label label4 = new Label();&lt;br /&gt;
      label4.Parent = this;&lt;br /&gt;
      label4.Text = &amp;quot;Status:&amp;quot;;&lt;br /&gt;
      label4.AutoSize = true;&lt;br /&gt;
      label4.Location = new Point(10, 325);&lt;br /&gt;
     &lt;br /&gt;
      status = new TextBox();&lt;br /&gt;
      status.Parent = this;&lt;br /&gt;
      status.Text = &amp;quot;Not connected&amp;quot;;&lt;br /&gt;
      status.Size = new Size(200, 2 * Font.Height);&lt;br /&gt;
      status.Location = new Point(50, 322);&lt;br /&gt;
      messages = new ListBox();&lt;br /&gt;
      messages.Parent = this;&lt;br /&gt;
      messages.Location = new Point(10, 108);&lt;br /&gt;
      messages.Size = new Size(360, 16 * Font.Height);&lt;br /&gt;
      messages.DoubleClick += new EventHandler(getmessagesDoubleClick);&lt;br /&gt;
      Button login = new Button();&lt;br /&gt;
      login.Parent = this;&lt;br /&gt;
      login.Text = &amp;quot;Login&amp;quot;;&lt;br /&gt;
      login.Location = new Point(295, 32);&lt;br /&gt;
      login.Size = new Size(5 * Font.Height, 2 * Font.Height);&lt;br /&gt;
      login.Click += new EventHandler(ButtonloginOnClick);&lt;br /&gt;
      Button close = new Button();&lt;br /&gt;
      close.Parent = this;&lt;br /&gt;
      close.Text = &amp;quot;Close&amp;quot;;&lt;br /&gt;
      close.Location = new Point(295, 62);&lt;br /&gt;
      close.Size = new Size(5 * Font.Height, 2 * Font.Height);&lt;br /&gt;
      close.Click += new EventHandler(ButtoncloseOnClick);&lt;br /&gt;
    }&lt;br /&gt;
   void ButtonloginOnClick(object obj, EventArgs ea)&lt;br /&gt;
   {&lt;br /&gt;
      status.Text = &amp;quot;Checking for messages...&amp;quot;;&lt;br /&gt;
      Thread startlogin = new Thread(new ThreadStart(loginandretr));&lt;br /&gt;
      startlogin.IsBackground = true;&lt;br /&gt;
      startlogin.Start();&lt;br /&gt;
   }&lt;br /&gt;
   void ButtoncloseOnClick(object obj, EventArgs ea)&lt;br /&gt;
   {&lt;br /&gt;
      if (ns != null)&lt;br /&gt;
      {&lt;br /&gt;
         sw.Close();&lt;br /&gt;
         sr.Close();&lt;br /&gt;
         ns.Close();&lt;br /&gt;
         mailclient.Close();&lt;br /&gt;
      }&lt;br /&gt;
      Close();&lt;br /&gt;
   }&lt;br /&gt;
   void loginandretr()&lt;br /&gt;
   {&lt;br /&gt;
      string response;&lt;br /&gt;
      string from = null;&lt;br /&gt;
      string subject = null;&lt;br /&gt;
      int totmessages;&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
         mailclient = new TcpClient(hostname.Text, 110);&lt;br /&gt;
      } catch (SocketException)&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;Unable to connect to server&amp;quot;;&lt;br /&gt;
         return;&lt;br /&gt;
      }&lt;br /&gt;
      ns = mailclient.GetStream();&lt;br /&gt;
      sr = new StreamReader(ns);&lt;br /&gt;
      sw = new StreamWriter(ns);&lt;br /&gt;
      response = sr.ReadLine(); //Get opening POP3 banner&lt;br /&gt;
      sw.WriteLine(&amp;quot;User &amp;quot; + username.Text); //Send username&lt;br /&gt;
      sw.Flush();&lt;br /&gt;
      response = sr.ReadLine();&lt;br /&gt;
      if (response.Substring(0,4) == &amp;quot;-ERR&amp;quot;)&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;Unable to log into server&amp;quot;;&lt;br /&gt;
         return;&lt;br /&gt;
      }&lt;br /&gt;
      sw.WriteLine(&amp;quot;Pass &amp;quot; + password.Text);  //Send password&lt;br /&gt;
      sw.Flush();&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
         response = sr.ReadLine();&lt;br /&gt;
      } catch (IOException)&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;Unable to log into server&amp;quot;;&lt;br /&gt;
         return;&lt;br /&gt;
      }&lt;br /&gt;
      if (response.Substring(0,3) == &amp;quot;-ER&amp;quot;)&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;Unable to log into server&amp;quot;;&lt;br /&gt;
         return;&lt;br /&gt;
      }&lt;br /&gt;
      sw.WriteLine(&amp;quot;stat&amp;quot;); //Send stat command to get number of messages&lt;br /&gt;
      sw.Flush();&lt;br /&gt;
      response = sr.ReadLine();&lt;br /&gt;
      string[] nummess = response.Split(&amp;quot; &amp;quot;);&lt;br /&gt;
      totmessages = Convert.ToInt16(nummess[1]);&lt;br /&gt;
      if (totmessages &amp;gt; 0)&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;you have &amp;quot; + totmessages + &amp;quot; messages&amp;quot;;&lt;br /&gt;
      } else&lt;br /&gt;
      {&lt;br /&gt;
         status.Text = &amp;quot;You have no messages&amp;quot; ;&lt;br /&gt;
      }&lt;br /&gt;
      for (int i = 1; i &amp;lt;= totmessages; i++)&lt;br /&gt;
      {&lt;br /&gt;
         sw.WriteLine(&amp;quot;top &amp;quot; + i + &amp;quot; 0&amp;quot;); //read header of each message&lt;br /&gt;
         sw.Flush();&lt;br /&gt;
         response = sr.ReadLine();&lt;br /&gt;
         while (true)&lt;br /&gt;
         {&lt;br /&gt;
            response = sr.ReadLine();&lt;br /&gt;
            if (response == &amp;quot;.&amp;quot;)&lt;br /&gt;
               break;&lt;br /&gt;
            if (response.Length &amp;gt; 4)&lt;br /&gt;
            {&lt;br /&gt;
               if (response.Substring(0, 5) == &amp;quot;From:&amp;quot;)&lt;br /&gt;
                  from = response;&lt;br /&gt;
               if (response.Substring(0, 8) == &amp;quot;Subject:&amp;quot;)&lt;br /&gt;
                  subject = response;&lt;br /&gt;
            }&lt;br /&gt;
         }&lt;br /&gt;
         messages.Items.Add(i + &amp;quot;  &amp;quot; + from + &amp;quot;  &amp;quot; + subject);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
   void getmessagesDoubleClick(object obj, EventArgs ea)&lt;br /&gt;
   {&lt;br /&gt;
      string text = (string)messages.SelectedItem;&lt;br /&gt;
      string[] textarray = text.Split(&amp;quot; &amp;quot;);&lt;br /&gt;
      ShowMessage sm = new ShowMessage(ns, textarray[0]);&lt;br /&gt;
      sm.ShowDialog();&lt;br /&gt;
   }&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      Application.Run(new PopCheck());&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
class ShowMessage : Form&lt;br /&gt;
{&lt;br /&gt;
   public ShowMessage(NetworkStream ns, string messnumber)&lt;br /&gt;
   {&lt;br /&gt;
      StreamReader sr = new StreamReader(ns);&lt;br /&gt;
      StreamWriter sw = new StreamWriter(ns);&lt;br /&gt;
      string response;&lt;br /&gt;
      Text = &amp;quot;Message &amp;quot; + messnumber;&lt;br /&gt;
      Size = new Size(400, 380);&lt;br /&gt;
      ShowInTaskbar = false;&lt;br /&gt;
      TextBox display = new TextBox();&lt;br /&gt;
      display.Parent = this;&lt;br /&gt;
      display.Multiline = true;&lt;br /&gt;
      display.Dock = DockStyle.Fill;&lt;br /&gt;
      display.ScrollBars = ScrollBars.Both;&lt;br /&gt;
      sw.WriteLine(&amp;quot;retr &amp;quot; + messnumber); //Retrieve entire message&lt;br /&gt;
      sw.Flush();&lt;br /&gt;
      response = sr.ReadLine();&lt;br /&gt;
      while (true)&lt;br /&gt;
      {&lt;br /&gt;
         response = sr.ReadLine();&lt;br /&gt;
         if (response == &amp;quot;.&amp;quot;)&lt;br /&gt;
            break;&lt;br /&gt;
         display.Text += response + &amp;quot;\r\n&amp;quot;;&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Fancy Mail Test==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Network Programming &lt;br /&gt;
by Richard Blum&lt;br /&gt;
Publisher: Sybex &lt;br /&gt;
ISBN: 0782141765&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Web.Mail;&lt;br /&gt;
public class FancyMailTest&lt;br /&gt;
{&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MailMessage mm = new MailMessage();&lt;br /&gt;
      mm.From = &amp;quot;haley@myisp.net&amp;quot;;&lt;br /&gt;
      mm.To = &amp;quot;riley@yourisp.net;rich@shadrach.ispnet1.net&amp;quot;;&lt;br /&gt;
      mm.Cc = &amp;quot;matthew@anotherisp.net;chris@hisisp.net&amp;quot;;&lt;br /&gt;
      mm.Bcc = &amp;quot;katie@herisp.net;jessica@herisp.net&amp;quot;;&lt;br /&gt;
      mm.Subject = &amp;quot;This is a fancy test message&amp;quot;;&lt;br /&gt;
      mm.Headers.Add(&amp;quot;Reply-To&amp;quot;, &amp;quot;haley@myisp.net&amp;quot;);&lt;br /&gt;
      mm.Headers.Add(&amp;quot;Comments&amp;quot;, &amp;quot;This is a test HTML message&amp;quot;);&lt;br /&gt;
      mm.Priority = MailPriority.High;&lt;br /&gt;
      mm.BodyFormat = MailFormat.Html;&lt;br /&gt;
      mm.Body = &amp;quot;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;This is a test message&amp;lt;/h1&amp;gt;&amp;lt;h2&amp;gt;This message should have HTML-type formatting&amp;lt;/h2&amp;gt;Please use an HTML-capable viewer.&amp;quot;;&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
         SmtpMail.Send(mm);&lt;br /&gt;
      } catch (System.Web.HttpException)&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;This device is unable to send Internet messages&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Mail Attach Test==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Network Programming &lt;br /&gt;
by Richard Blum&lt;br /&gt;
Publisher: Sybex &lt;br /&gt;
ISBN: 0782141765&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Web.Mail;&lt;br /&gt;
public class MailAttachTest&lt;br /&gt;
{&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      MailAttachment myattach =&lt;br /&gt;
          new MailAttachment(&amp;quot;c:\\temp\\MailAttachTest.exe&amp;quot;, MailEncoding.Base64);&lt;br /&gt;
      MailMessage newmessage = new MailMessage();&lt;br /&gt;
      newmessage.From = &amp;quot;barbara@shadrach.ispnet1.net&amp;quot;;&lt;br /&gt;
      newmessage.To = &amp;quot;rich@shadrach.ispnet1.net&amp;quot;;&lt;br /&gt;
      newmessage.Subject = &amp;quot;A test mail attachment message&amp;quot;;&lt;br /&gt;
      newmessage.Priority = MailPriority.High;&lt;br /&gt;
      newmessage.Headers.Add(&amp;quot;Comments&amp;quot;,&lt;br /&gt;
                 &amp;quot;This message attempts to send a binary attachment&amp;quot;);&lt;br /&gt;
      newmessage.Attachments.Add(myattach);&lt;br /&gt;
      newmessage.Body = &amp;quot;Here&amp;quot;s a test file for you to try&amp;quot;;&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
         SmtpMail.SmtpServer = &amp;quot;192.168.1.100&amp;quot;;&lt;br /&gt;
         SmtpMail.Send(newmessage);&lt;br /&gt;
      } catch (System.Web.HttpException)&lt;br /&gt;
      {&lt;br /&gt;
         Console.WriteLine(&amp;quot;This device can not send Internet messages&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Mail Test==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Web.Mail;&lt;br /&gt;
public class MailTest&lt;br /&gt;
{&lt;br /&gt;
   public static void Main()&lt;br /&gt;
   {&lt;br /&gt;
      string from = &amp;quot;from@from.net&amp;quot;;&lt;br /&gt;
      string to = &amp;quot;to@to.net&amp;quot;;&lt;br /&gt;
      string subject = &amp;quot;This is a test mail message&amp;quot;;&lt;br /&gt;
      string body = &amp;quot;Hi .&amp;quot;;&lt;br /&gt;
      SmtpMail.SmtpServer = &amp;quot;192.168.1.150&amp;quot;;&lt;br /&gt;
      SmtpMail.Send(from, to, subject, body);&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==SmtpClient: From, Subject, Body, Attachments, To==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Mail;&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main(string[] args) {&lt;br /&gt;
        SmtpClient client = new SmtpClient(&amp;quot;mail.somecompany.ru&amp;quot;, 25);&lt;br /&gt;
        client.Credentials = new NetworkCredential(&amp;quot;user@somecompany.ru&amp;quot;, &amp;quot;password&amp;quot;);&lt;br /&gt;
        using (MailMessage msg = new MailMessage()) {&lt;br /&gt;
            msg.From = new MailAddress(&amp;quot;author@visual-csharp-recipes.ru&amp;quot;);&lt;br /&gt;
            msg.Subject = &amp;quot;Greetings&amp;quot;;&lt;br /&gt;
            msg.Body = &amp;quot;This is a  message.&amp;quot;;&lt;br /&gt;
            msg.Attachments.Add(new Attachment(&amp;quot;7.cs&amp;quot;, &amp;quot;text/plain&amp;quot;));&lt;br /&gt;
            msg.Attachments.Add(new Attachment(&amp;quot;7.exe&amp;quot;, &amp;quot;application/octet-stream&amp;quot;));&lt;br /&gt;
            foreach (string str in args) {&lt;br /&gt;
                try {&lt;br /&gt;
                    msg.To.Add(new MailAddress(str));&lt;br /&gt;
                } catch (FormatException ex) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;{0}: Error -- {1}&amp;quot;, str, ex.Message);&lt;br /&gt;
                    continue;&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            client.Send(msg);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>