receiveLetter.cs
上传用户:hncsjykj
上传日期:2022-08-09
资源大小:461k
文件大小:4k
源码类别:

Email客户端

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using OpenPOP.POP3;
  9. using System.Collections;
  10. using OpenPOP.MIMEParser;
  11. namespace LYBemail
  12. {
  13.     public partial class receiveLetter : Form
  14.     {
  15.         ReceiveMail messageBox;
  16.         private string txtmessage="";
  17.         private OpenPOP.MIMEParser.Message m = null;
  18.         public receiveLetter()
  19.         {
  20.             InitializeComponent();
  21.             readButton.Enabled = false;
  22.             changeButton.Enabled = false;
  23.             messageNO.ReadOnly = true;
  24.         }
  25.         private void init()
  26.         {
  27.             readButton.Enabled = false;
  28.             messageNO.ReadOnly = true;
  29.             string popServer = txtPOP.Text;
  30.             string login = txtLogin.Text;
  31.             string password = txtPassword.Text;
  32.             messageBox = new ReceiveMail(popServer, txt_port.Text,login,password);
  33.             int count = messageBox.connect();
  34.             messageCount.Text = count + "";
  35.             changeButton.Enabled = false;
  36.             subjectText.Text = "";
  37.             attachmentName.Text = "";
  38.             txtPanel.Controls.Clear();
  39.             readButton.Enabled = true;
  40.             messageNO.ReadOnly = false;
  41.         }
  42.         private void readButton_Click(object sender, EventArgs e)
  43.         {
  44.             changeButton.Enabled = true;
  45.             subjectText.Text = "";
  46.             attachmentName.Text = "";
  47.             int index = Int16.Parse(messageNO.Text);
  48.             bool hasAttachment = messageBox.setMessage(index);
  49.             ArrayList name = new ArrayList();
  50.             m = messageBox.currentMessage;
  51.             int count = m.AttachmentCount;
  52.             for (int i = 0; i < count; i++)
  53.             {
  54.                 if (m.GetAttachment(i).NotAttachment)
  55.                     continue;
  56.                 Attachment at1 = m.GetAttachment(i);
  57.                 
  58.                 name.Add(m.GetAttachmentFileName(at1));
  59.             }
  60.                  messageBox.setMessage(index);
  61.                 int number = name.Count;
  62.                 string names = "";
  63.                 for (int i = 0; i < number; i++)
  64.                 {
  65.                     names = names + name[i].ToString() + " ";
  66.                 }
  67.                 attachmentName.Text = names;
  68.             subjectText.Text = m.Subject;
  69.             if (m.MessageBody.Count != 0)
  70.                 txtmessage = (string)m.MessageBody[0];
  71.             else
  72.                 txtmessage = "";
  73.             
  74.             showMessage(!m.HTML);
  75.         }
  76.         private void showMessage(bool HTML)
  77.         {
  78.             if (!HTML)
  79.             {
  80.                 txtPanel.Controls.Clear();
  81.                 TextBox txtBox = new TextBox();
  82.                 txtBox.Multiline = true;
  83.                 txtBox.Text = txtmessage;
  84.                 txtBox.ReadOnly = true;
  85.                 txtPanel.Controls.Add(txtBox);
  86.                 txtBox.Dock = DockStyle.Fill;
  87.                 changeButton.Text = "切换至HTML格式";
  88.             }
  89.             else
  90.             {
  91.                 txtPanel.Controls.Clear();
  92.                 WebBrowser txtBox = new WebBrowser();
  93.                 txtBox.DocumentText = txtmessage;
  94.                 txtPanel.Controls.Add(txtBox);
  95.                 txtBox.Dock = DockStyle.Fill;
  96.                 changeButton.Text = "切换至文本格式";
  97.             }
  98.             textFrom.Text = m.From + "<" + m.FromEmail + ">";
  99.             try
  100.             {
  101.               textTo.Text = m.TO[0];
  102.             }
  103.             catch (Exception e)
  104.             {
  105.                 textTo.Text = e.Message;
  106.             }
  107.             
  108.         }
  109.         private void saveButton_Click(object sender, EventArgs e)
  110.         {
  111.             messageBox.getAttachments("d:");
  112.         }
  113.         private void changeButton_Click(object sender, EventArgs e)
  114.         {
  115.             if (changeButton.Text == "切换至HTML格式")
  116.                 showMessage(true);
  117.             else
  118.                 showMessage(false);
  119.         }
  120.         private void button1_Click(object sender, EventArgs e)
  121.         {
  122.             init();
  123.         }
  124.         private void txtPassword_TextChanged(object sender, EventArgs e)
  125.         {
  126.         
  127.         }
  128.         private void frmCuteMail_Load(object sender, EventArgs e)
  129.         {
  130.         
  131.         }
  132.     }
  133. }