receiveLetter.cs
资源名称:Email.rar [点击查看]
上传用户:hncsjykj
上传日期:2022-08-09
资源大小:461k
文件大小:4k
源码类别:
Email客户端
开发平台:
C#
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using OpenPOP.POP3;
- using System.Collections;
- using OpenPOP.MIMEParser;
- namespace LYBemail
- {
- public partial class receiveLetter : Form
- {
- ReceiveMail messageBox;
- private string txtmessage="";
- private OpenPOP.MIMEParser.Message m = null;
- public receiveLetter()
- {
- InitializeComponent();
- readButton.Enabled = false;
- changeButton.Enabled = false;
- messageNO.ReadOnly = true;
- }
- private void init()
- {
- readButton.Enabled = false;
- messageNO.ReadOnly = true;
- string popServer = txtPOP.Text;
- string login = txtLogin.Text;
- string password = txtPassword.Text;
- messageBox = new ReceiveMail(popServer, txt_port.Text,login,password);
- int count = messageBox.connect();
- messageCount.Text = count + "";
- changeButton.Enabled = false;
- subjectText.Text = "";
- attachmentName.Text = "";
- txtPanel.Controls.Clear();
- readButton.Enabled = true;
- messageNO.ReadOnly = false;
- }
- private void readButton_Click(object sender, EventArgs e)
- {
- changeButton.Enabled = true;
- subjectText.Text = "";
- attachmentName.Text = "";
- int index = Int16.Parse(messageNO.Text);
- bool hasAttachment = messageBox.setMessage(index);
- ArrayList name = new ArrayList();
- m = messageBox.currentMessage;
- int count = m.AttachmentCount;
- for (int i = 0; i < count; i++)
- {
- if (m.GetAttachment(i).NotAttachment)
- continue;
- Attachment at1 = m.GetAttachment(i);
- name.Add(m.GetAttachmentFileName(at1));
- }
- messageBox.setMessage(index);
- int number = name.Count;
- string names = "";
- for (int i = 0; i < number; i++)
- {
- names = names + name[i].ToString() + " ";
- }
- attachmentName.Text = names;
- subjectText.Text = m.Subject;
- if (m.MessageBody.Count != 0)
- txtmessage = (string)m.MessageBody[0];
- else
- txtmessage = "";
- showMessage(!m.HTML);
- }
- private void showMessage(bool HTML)
- {
- if (!HTML)
- {
- txtPanel.Controls.Clear();
- TextBox txtBox = new TextBox();
- txtBox.Multiline = true;
- txtBox.Text = txtmessage;
- txtBox.ReadOnly = true;
- txtPanel.Controls.Add(txtBox);
- txtBox.Dock = DockStyle.Fill;
- changeButton.Text = "切换至HTML格式";
- }
- else
- {
- txtPanel.Controls.Clear();
- WebBrowser txtBox = new WebBrowser();
- txtBox.DocumentText = txtmessage;
- txtPanel.Controls.Add(txtBox);
- txtBox.Dock = DockStyle.Fill;
- changeButton.Text = "切换至文本格式";
- }
- textFrom.Text = m.From + "<" + m.FromEmail + ">";
- try
- {
- textTo.Text = m.TO[0];
- }
- catch (Exception e)
- {
- textTo.Text = e.Message;
- }
- }
- private void saveButton_Click(object sender, EventArgs e)
- {
- messageBox.getAttachments("d:");
- }
- private void changeButton_Click(object sender, EventArgs e)
- {
- if (changeButton.Text == "切换至HTML格式")
- showMessage(true);
- else
- showMessage(false);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- init();
- }
- private void txtPassword_TextChanged(object sender, EventArgs e)
- {
- }
- private void frmCuteMail_Load(object sender, EventArgs e)
- {
- }
- }
- }