www.pudn.com > MailAccess.rar > ServerSetting.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using OpenPOP.MIMEParser;
using OpenPOP.POP3;
using OpenSmtp.Mail;
namespace LotusServer
{
///
/// Summary description for Form1.
///
public class ServerSetting : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtServer;
private System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Button btnSubmit;
private System.Windows.Forms.Label lblMassages;
private System.Windows.Forms.Label lblCount;
private POPClient popClient=new POPClient();
private System.Windows.Forms.Label lblMassage1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public ServerSetting()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ServerSetting));
this.txtServer = new System.Windows.Forms.TextBox();
this.txtPort = new System.Windows.Forms.TextBox();
this.txtUsername = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnSubmit = new System.Windows.Forms.Button();
this.lblMassages = new System.Windows.Forms.Label();
this.lblCount = new System.Windows.Forms.Label();
this.lblMassage1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtServer
//
this.txtServer.Location = new System.Drawing.Point(88, 8);
this.txtServer.Name = "txtServer";
this.txtServer.Size = new System.Drawing.Size(272, 21);
this.txtServer.TabIndex = 0;
this.txtServer.Text = "";
//
// txtPort
//
this.txtPort.Location = new System.Drawing.Point(88, 32);
this.txtPort.Name = "txtPort";
this.txtPort.Size = new System.Drawing.Size(272, 21);
this.txtPort.TabIndex = 1;
this.txtPort.Text = "";
//
// txtUsername
//
this.txtUsername.Location = new System.Drawing.Point(88, 56);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(272, 21);
this.txtUsername.TabIndex = 2;
this.txtUsername.Text = "";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(88, 80);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(272, 21);
this.txtPassword.TabIndex = 3;
this.txtPassword.Text = "";
//
// btnSubmit
//
this.btnSubmit.Location = new System.Drawing.Point(496, 264);
this.btnSubmit.Name = "btnSubmit";
this.btnSubmit.TabIndex = 4;
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
//
// lblMassages
//
this.lblMassages.Location = new System.Drawing.Point(8, 176);
this.lblMassages.Name = "lblMassages";
this.lblMassages.Size = new System.Drawing.Size(568, 23);
this.lblMassages.TabIndex = 5;
//
// lblCount
//
this.lblCount.Location = new System.Drawing.Point(8, 136);
this.lblCount.Name = "lblCount";
this.lblCount.Size = new System.Drawing.Size(568, 23);
this.lblCount.TabIndex = 6;
//
// lblMassage1
//
this.lblMassage1.Location = new System.Drawing.Point(0, 216);
this.lblMassage1.Name = "lblMassage1";
this.lblMassage1.Size = new System.Drawing.Size(568, 23);
this.lblMassage1.TabIndex = 7;
//
// ServerSetting
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(576, 293);
this.Controls.Add(this.lblMassage1);
this.Controls.Add(this.lblCount);
this.Controls.Add(this.lblMassages);
this.Controls.Add(this.btnSubmit);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.txtPort);
this.Controls.Add(this.txtServer);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "ServerSetting";
this.Text = "ServerSetting";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.ServerSetting_Load);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new ServerSetting());
}
private void DataInit()
{
txtServer.Text="Harrison.suzsoft.com";
txtPort.Text="110";
txtUsername.Text="muhan";
txtPassword.Text="muhan";
btnSubmit.Text="Submit";
}
private void ServerSetting_Load(object sender, System.EventArgs e)
{
DataInit();
}
private void ReceiveMails()
{
OpenPOP.POP3.Utility.Log=true;
popClient.Disconnect();
popClient.Connect(txtServer.Text,int.Parse(txtPort.Text));
popClient.Authenticate(txtUsername.Text,txtPassword.Text);
int Count=popClient.GetMessageCount();
lblCount.Text=Count.ToString();
for(int i=Count;i>=1;i-=1)
{
OpenPOP.MIMEParser.Message GetMail=popClient.GetMessage(i,false);
if(GetMail!=null)
{
string strRes=GetMail.FromEmail.ToString();
// OpenPOP.MIMEParser.Attachment[] attachmen=null;
OpenPOP.MIMEParser.Attachment attachment=null;
// string[] strAttachmentFileName=null;
switch(strRes)
{
case "muhan@muhan.com":
{
for (int j=0;j<=GetMail.AttachmentCount-1;j++)
{
attachment=GetMail.GetAttachment(j);
lblMassages.Text=GetMail.GetAttachmentFileName(attachment);
int k=lblMassages.Text.IndexOf(".");
if (lblMassages.Text.Substring(k,4)!=".htm")
{
GetMail.SaveAttachments("C:\\MailAttachments\\muhan");
GetMail.SaveAttachment(attachment,lblMassages.Text);
GetMail.SaveAttachments("C:\\MailAttachments\\muhanbackup");
GetMail.SaveAttachment(attachment,lblMassages.Text);
}
}
//popClient.DeleteMessage(i);
break;
}
case "muhan1@muhan.com":
{
for (int j=0;j<=GetMail.AttachmentCount-1;j++)
{
attachment=GetMail.GetAttachment(j);
lblMassage1.Text=GetMail.GetAttachmentFileName(attachment);
GetMail.SaveAttachments("C:\\MailAttachments\\muhan1");
GetMail.SaveAttachment(attachment,lblMassages.Text);
GetMail.SaveAttachments("C:\\MailAttachments\\muhan1backup");
GetMail.SaveAttachment(attachment,lblMassages.Text);}
break;
}
//
}
}
else
{
}
}
// MessageBox.Show(this,"mail received!");
}
private void btnSubmit_Click(object sender, System.EventArgs e)
{
ReceiveMails();
}
}
}