c#封装jmail的pop3收邮件

jmail|封装|收邮件

*
w3 JMail v4.4 Professional 的获取请自行 google!
或参阅 http://community.csdn.net/Expert/TopicView.asp?id=3739405
w3 JMail v4.4 Professional 是一个 COM 的组件,我用 C# 把其 POP3 COM 类封装成
一个用于收取邮件的 .Net 组件:
实现了
 //同步事件
  public event MessagesEventHandler MessageReceived; //一封邮件已收到本地
  public event MessagesEventHandler MessageReceive; //一封邮件正到达
  //可用于收取邮件的每个附件处理
  public event AttachmentsEventHandler AttachmentReceive; //一封邮件的附件正到达

 //发生异常事件
  public event MessagesEventHandler MessageException;
  public event AttachmentsEventHandler AttachmentException;

因此在调用该组件的主调程序中可根据分析邮件的主题或附件等结果作不同处理!

将如下所有代码:
1.复制到 Microsoft Visual Studio .Net 2003 的新建的 "控制台应用程序" 项目的 *.cs 文件中
2.然后添加引用 JMail 4.x Library!
jmail 的注册方法,运行命令行: regsvr32 e:\jmail\jmail.dll
3.F5 运行

或者
将如下所有代码:
1.复制到任意一个 *.cs 文件中保存!(如: e:\temp\NJMail.cs)
2.使用 tlbimp.exe(类型库导入程序)实用工具生成一个 .Net 程序集
执行命令行: (位于 Ms VS.Net 安装目录下的: E:\MsVS.Net\SDK\v1.1\Bin\TlbImp.exe)
tlbimp.exe e:\jmail\jmail.dll /out:e:\temp\jmail.net.dll /namespace:jmail
生成的 jmail.net.dll 与 *.cs 文件放在同一目录下!
3.执行 csc 命令行编译 *.cs
编译成 exe : (这里是为了演示测试效果所以编译成 exe)
csc.exe NJMail.cs /r:jmail.net.dll
编译成 dll ,即可由别的 .Net 程序添加引用:
csc.exe /t:library NJMail.cs /r:jmail.net.dll

(当然也可将 namespace Microshaoft.NJMail 下的代码单独编译成 dll)
*/

namespace Microshaoft.NJMail
{
 //using jmail;
 //using System;

 public class POP3
 {
  public delegate void MessagesEventHandler(MessagesState oMessagesState);
  public delegate void AttachmentsEventHandler(AttachmentsState oAttachmentsState);

  //异步事件
  public event MessagesEventHandler MessagesReceiveAsync;
  public event AttachmentsEventHandler AttachmentsReceiveAsync;

  //同步事件
  public event MessagesEventHandler MessageReceived;
  public event MessagesEventHandler MessageReceive;
  public event AttachmentsEventHandler AttachmentReceive;

  //发生异常事件
  public event MessagesEventHandler MessageException;
  public event AttachmentsEventHandler AttachmentException;

  private string _UserName;
  private string _Password;
  private string _Server;
  private int _Port = 110;

  private static object _LockObject = new object();

  public POP3(string UserName,string Password,string Server,int Port)
  {
   this._UserName = UserName;
   this._Password = Password;
   this._Server = Server;
   this._Port = Port;
  }

  public POP3(string UserName,string Password,string Server)
  {
   this._UserName = UserName;
   this._Password = Password;
   this._Server = Server;
  }

  //[MTAThread]
  public void Execute()
  {
   this.Execute(false);
  }

  public void Execute(bool IsAsync)
  {
   jmail.POP3Class pop3 = new jmail.POP3Class();
   try
   {
    pop3.Timeout = 0;
    pop3.Connect(this._UserName,this._Password,this._Server,this._Port);
    jmail.MessagesClass jms = (jmail.MessagesClass) pop3.Messages;
    int I = jms.Count;
    MessagesState omss = null;
    for (int i = 0; i < I - 1; i++)
    {
     try
     {
      jmail.MessageClass jmc = (jmail.MessageClass) jms[i+1];
      if (omss == null)
      {
       omss = new MessagesState(i+1,jmc,jms,pop3);
       if (this.MessageReceive != null)
       {
        this.MessageReceive(omss);
       }
      }
      if (!omss.CancelCurrent)
      {
       if (IsAsync)
       {
        //System.IAsyncResult iar =
        (new MessagesEventHandler(this.MessageExecuteAsync)).BeginInvoke(omss,new System.AsyncCallback(this.OnMessageCallBack),omss);
       }
       else
       {
        int J = jmc.Attachments.Count;
        AttachmentsState oass = null;
        for (int j = 0; j < J; j++)
        {
         try
         {
          if (oass == null)
          {
           oass = new AttachmentsState(j,omss);
           if (this.AttachmentReceive != null)
           {
            this.AttachmentReceive(oass);
           }
          }
          if (!oass.CancelCurrent)
          {
           string s = oass.FileName;
           omss.SetFilePath(System.IO.Path.GetDirectoryName(s) + @"\");
           oass.SaveToFile(s);
          }
         }
         catch (System.Exception e)
         {
          if (this.AttachmentException != null)
          {
           oass.Exception = e;
           this.AttachmentException(oass);
           if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.CancelAll)
           {
            break;
           }
           else
           if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Retry)
           {
            j--;
           }
           else
           if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Ignore)
           {
            //continue;
           }
           else
           if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Throw)
           {
            throw e;
           }
          }
          else
          {
           throw e;
          }
         }
        }
        if (this.MessageReceived != null)
        {
         this.MessageReceived(omss);
        }
       }
      }
     }
     catch (System.Exception e)
     {
      if (this.MessageException != null)
      {
       omss.Exception = e;
       this.MessageException(omss);
       if (omss.ExceptionAction == Microshaoft.NJMail.ExceptionActions.CancelAll)
       {
        break;
       }
       else
       if (omss.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Retry)
       {
        i--;
       }
       else
       if (omss.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Ignore)
       {
        //continue;
       }
       else
       if (omss.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Throw)
       {
        throw e;
       }
      }
      else
      {
       throw e;
      }
     }
    }
   }
   catch (System.Exception e)
   {
    throw e;
   }
   finally
   {
    pop3.Disconnect();
    pop3 = null;
   }
   //System.Console.WriteLine("main end");
  }

  //[MTAThread]
  private void MessageExecuteAsync(MessagesState oMessagesState)
  {
   int J = oMessagesState.jMessage.Attachments.Count;
   for (int j = 0; j < J; j++)
   {
    AttachmentsState oass = new AttachmentsState(j,oMessagesState);
    //System.IAsyncResult iar =
    (new AttachmentsEventHandler(this.AttachmentExecuteAsync)).BeginInvoke(oass,new System.AsyncCallback(this.OnAttachemnetCallBack),oass);
   }
  }

  //[MTAThread]
  private void AttachmentExecuteAsync(AttachmentsState oAttachmentsState)
  {
   //
  }

  //[MTAThread]
  private void OnMessageCallBack(System.IAsyncResult iar)
  {
   MessagesState omss = (MessagesState) iar.AsyncState;
   if (this.MessagesReceiveAsync != null)
   {
    if (omss.jMessage.Attachments.Count == 0)
    {
     this.MessagesReceiveAsync(omss);
    }
   }
  }

  //[MTAThread]
  private void OnAttachemnetCallBack(System.IAsyncResult iar)
  {
   AttachmentsState oass = (AttachmentsState) iar.AsyncState;
   if (this.AttachmentsReceiveAsync != null)
   {
    this.AttachmentsReceiveAsync(oass);
   }
   if (!oass.CancelCurrent)
   {
    try
    {
     oass.SaveToFile(oass.FileName);
    }
    catch (System.Exception e)
    {
     oass.Exception = e;
     if (AttachmentException != null)
     {
      AttachmentException(oass);
      if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.CancelAll)
      {

      }
      else
      if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Retry)
      {
       this.OnAttachemnetCallBack((System.IAsyncResult) oass);
      }
      else
      if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Ignore)
      {

      }
      else
      if (oass.ExceptionAction == Microshaoft.NJMail.ExceptionActions.Throw)
      {
       throw e;
      }
     }
    }
   }
   if (this.MessagesReceiveAsync != null)
   {
    if (oass.AttachmentsCount == 0)
    {
     this.MessagesReceiveAsync(oass.MessagesState);
    }
   }
  }
 }

 public class MessagesState //Messages 状态
 {
  private static object _LockObject = new object();
  private int _MessageID;
  private jmail.MessageClass _jMessage;
  private jmail.MessagesClass _jMessages;
  private jmail.POP3Class _jPOP3;
  private string _FilePath;
  private bool _CancelCurrent;

  private System.Exception _Exception;
  private ExceptionActions _ExceptionAction;

 

  public ExceptionActions ExceptionAction
  {
   get
   {
    return _ExceptionAction;
   }
   set
   {
    this._ExceptionAction = value;
   }
  }

  public System.Exception Exception
  {
   get
   {
    return _Exception;
   }
   set
   {
    this._Exception = value;
   }
  }

  public string FilePath
  {
   get
   {
    return this._FilePath;
   }
  }

  internal void SetFilePath(string FilePath)
  {
   this._FilePath = FilePath;
  }

  public bool CancelCurrent
  {
   get
   {
    return this._CancelCurrent;
   }
   set
   {
    this._CancelCurrent = value;
   }
  }

  public int MessagesCount //尚未处理的邮件数
  {
   get
   {
    //lock(MessagesState._LockObject)
    {
     return this._jMessages.Count - this._MessageID - 1;
    }
   }
  }

  public jmail.MessagesClass jMessages
  {
   get
   {
    return this._jMessages;
   }
  }

  public jmail.MessageClass jMessage
  {
   get
   {
    return this._jMessage;
   }
  }

  public int MessageID
  {
   get
   {
    return this._MessageID;
   }
  }

  internal MessagesState(int MessageID,jmail.MessageClass jMessage,jmail.MessagesClass jMessages,jmail.POP3Class jPOP3)
  {
   this._MessageID = MessageID;
   this._jMessage = jMessage;
   this._jMessages = jMessages;
   this._jPOP3 = jPOP3;
  }

  public void DeleteSingleMessage()
  {
   lock(MessagesState._LockObject)
   {
    this.DeleteSingleMessage(this._MessageID);
   }
  
  }

  public void DeleteSingleMessage(int MessageID)
  {
   lock(MessagesState._LockObject)
   {
    this._jPOP3.DeleteSingleMessage(MessageID);
   }
  }

  public void DeleteMessages()
  {
   lock(MessagesState._LockObject)
   {
    this._jPOP3.DeleteMessages();
   }
  }
 }

 public enum ExceptionActions
 {
  CancelAll,Ignore,Retry,Throw
 }

 public class AttachmentsState //Attachments 状态
 {
  private MessagesState _MessagesState;
  private int _AttachmentID;
  private string _FileName;
  private static object _LockObject = new object();
  private jmail.AttachmentClass _jAttachment;
  private bool _CancelCurrent;
  private System.Exception _Exception;
  private ExceptionActions _ExceptionAction;

  public ExceptionActions ExceptionAction
  {
   get
   {
    return _ExceptionAction;
   }
   set
   {
    this._ExceptionAction = value;
   }
  }

  public System.Exception Exception
  {
   get
   {
    return _Exception;
   }
   set
   {
    this._Exception = value;
   }
  }

  public bool CancelCurrent
  {
   get
   {
    return this._CancelCurrent;
   }
   set
   {
    this._CancelCurrent = value;
   }
  }

  public jmail.AttachmentClass jAttachment
  {
   get
   {
    return this._jAttachment;
   }
  }

  public int AttachmentsCount //尚未处理的邮件附件数
  {
   get
   {
    //lock(AttachmentsState._LockObject)
    {
     return this._MessagesState.jMessage.Attachments.Count - this._AttachmentID - 1;
    }
   }
  }

  public string FileName
  {
   get
   {
    return this._FileName;
   }
   set
   {
    this._FileName = value;
   }
  }

  public MessagesState MessagesState
  {
   get
   {
    return this._MessagesState;
   }
  }

  public int AttachmentID
  {
   get
   {
    return this._AttachmentID;
   }
  }

  public void SaveToFile(string FileName)
  {
   //if (!this.CancelCurrent)
   {
    this._jAttachment.SaveToFile(FileName);
   }
  }

  internal AttachmentsState(int AttachmentID,MessagesState oMessagesState)
  {
   this._MessagesState = oMessagesState;
   this._AttachmentID = AttachmentID;
   this._jAttachment = (jmail.AttachmentClass) oMessagesState.jMessage.Attachments[AttachmentID];
   this._FileName = System.String.Format("[{0}].{1}.[{2}].{3}",oMessagesState.MessageID,oMessagesState.jMessage.Subject,AttachmentID,this._jAttachment.Name);
  }
 }
}

//================================================================================================
//控制台测试程序:
namespace ConsoleApplicationTest
{
 using Microshaoft.NJMail;
 using POP = Microshaoft.NJMail.POP3;
 class AppTest
 {
  POP Pop1;
  bool IsBusy = false;

  static void Main()
  {

   //调用 Windows 测试程序
   System.Console.WriteLine("WindowsApplicationTest Begin:");
   WindowsApplicationTest.Form1.Main0();
   System.Console.WriteLine("WindowsApplicationTest End.");

   System.Console.WriteLine("ConsoleApplicationTest Begin:");
   AppTest a = new AppTest();
   a.Pop1 = new POP("UserName","Password","mail.xxx.com");
   //订阅异步事件
   a.Pop1.MessagesReceiveAsync += new Microshaoft.NJMail.POP3.MessagesEventHandler(a.Pop1_MessagesReceiveAsync);
   a.Pop1.AttachmentsReceiveAsync += new Microshaoft.NJMail.POP3.AttachmentsEventHandler(a.Pop1_AttachmentsReceiveAsync);
   //订阅同步事件
   a.Pop1.MessageReceived += new Microshaoft.NJMail.POP3.MessagesEventHandler(a.Pop1_MessageReceived);
   a.Pop1.AttachmentReceive += new Microshaoft.NJMail.POP3.AttachmentsEventHandler(a.Pop1_AttachmentReceive);
   a.Pop1.MessageReceive += new Microshaoft.NJMail.POP3.MessagesEventHandler(a.Pop1_MessageReceive);
   //订阅 Exception 事件
   a.Pop1.AttachmentException += new Microshaoft.NJMail.POP3.AttachmentsEventHandler(a.Pop1_AttachmentException);
   a.Run();
   System.Timers.Timer t = new System.Timers.Timer();
   t.Interval = 1000 * 30; //每 30 秒收取一次邮件
   t.Enabled = true;
   t.Elapsed += new System.Timers.ElapsedEventHandler(a.t_Elapsed);
   while (System.Console.ReadLine().ToLower() != "exit")
   {
    System.Console.WriteLine("press \"exit\" to exit this programe!");
   }
  }

  private void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  {
   this.Run();
  }

  private void Run()
  {
   if (!IsBusy)
   {
    System.Console.WriteLine("Busy");
    this.IsBusy = true;
    //this.Pop1.Execute(true); //异步执行
    this.Pop1.Execute(); //同步执行
    this.IsBusy = false;
    System.Console.WriteLine("Idle");
    System.Console.WriteLine("press \"exit\" to exit this programe!");
   }
  }

  private void Pop1_MessagesReceiveAsync(MessagesState oMessagesState)
  {
   System.Console.WriteLine("Message: [{0}].{1} of {2} Messages have been recieved! {3}",oMessagesState.MessageID,oMessagesState.jMessage.Subject,oMessagesState.jMessages.Count - 1,oMessagesState.MessagesCount);
   if (oMessagesState.MessagesCount == 0)
   {
    System.Console.WriteLine("all messages have been recieved!");
   }
  }

  private void Pop1_AttachmentsReceiveAsync(AttachmentsState oAttachmentsState)
  {
  
   oAttachmentsState.SaveToFile(@"E:\jmailAttachments\[" + System.Guid.NewGuid().ToString() + "]." +  oAttachmentsState.FileName);
   oAttachmentsState.FileName = @"E:\jmailAttachments\[" + System.Guid.NewGuid().ToString() + "]." +  oAttachmentsState.FileName;

   if (oAttachmentsState.AttachmentsCount == 0)
   {
    System.Console.WriteLine("[{0}].{1} have been recieved!",oAttachmentsState.MessagesState.MessageID,oAttachmentsState.MessagesState.jMessage.Subject);
    //异步执行删除有错误
    //oAttachmentsState.MessagesState.DeleteSingleMessage(oAttachmentsState.MessagesState.MessageID);
   }
   //oAttachmentsState.CancelCurrent = true;
  }

  private void Pop1_MessageReceived(MessagesState oMessagesState)
  {
   System.Console.WriteLine("Message: [{0}].{1} of {2} Messages have been recieved! {3}",oMessagesState.MessageID,oMessagesState.jMessage.Subject,oMessagesState.jMessages.Count - 1,oMessagesState.MessagesCount);
   //可以每收完一封邮件即删除
   //oMessagesState.DeleteSingleMessage(oMessagesState.MessageID);
  }

  private void Pop1_AttachmentReceive(AttachmentsState oAttachmentsState)
  {
   //oAttachmentsState.CancelCurrent = true;
   oAttachmentsState.SaveToFile(@"E:\jmailAttachments\[" + System.Guid.NewGuid().ToString() + "]." +  oAttachmentsState.FileName);
   oAttachmentsState.FileName = @"E:\jmailAttachments\[" + System.Guid.NewGuid().ToString() + "]." +  oAttachmentsState.FileName;
   //oAttachmentsState.CancelCurrent = true;
  }

  private void Pop1_MessageReceive(MessagesState oMessagesState)
  {
   //oMessagesState.CancelCurrent = false;
  }

  private void Pop1_AttachmentException(Microshaoft.NJMail.AttachmentsState oAttachmentsState)
  {
   System.Console.WriteLine("Execute Exception: {0}",oAttachmentsState.Exception.Message);
   oAttachmentsState.FileName ="e:\\temp\\copy of " + oAttachmentsState.jAttachment.Name;
   oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Retry; //上一句文件改名后重新处理
   oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Ignore; //处理下一个附件
   //oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Throw;
  }
 }
}

//================================================================================================
// Windows 测试程序:
namespace WindowsApplicationTest
{
 using System;
 using System.Windows.Forms;
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Timer timer1;
  private System.ComponentModel.IContainer components;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   this.button1 = new System.Windows.Forms.Button();
   this.timer1 = new System.Windows.Forms.Timer(this.components);
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(24, 24);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(80, 40);
   this.button1.TabIndex = 0;
   this.button1.Text = "button1";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // timer1
   //
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(292, 273);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  public static void Main0() //Main() //若要单独的 Windows 程序可再换回 Main()
  {
   Application.Run(new Form1());
  }
  private Microshaoft.NJMail.POP3 x;
  private void button1_Click(object sender, System.EventArgs e)
  {
   button1.Enabled = false;
   x = new Microshaoft.NJMail.POP3("UserName","Password","mail.xxx.com");
   x.MessageReceive += new Microshaoft.NJMail.POP3.MessagesEventHandler(x_MessageReceive);
   x.MessageReceived += new Microshaoft.NJMail.POP3.MessagesEventHandler(x_MessageReceived);
   x.AttachmentReceive += new Microshaoft.NJMail.POP3.AttachmentsEventHandler(x_AttachmentReceive);
   x.AttachmentException += new Microshaoft.NJMail.POP3.AttachmentsEventHandler(x_AttachmentException);
   timer1.Interval = 1000 * 120; //每 120 秒收取一次邮件
   timer1.Enabled = false;
   x.Execute();
   button1.Enabled = true;
  }

  private void x_MessageReceive(Microshaoft.NJMail.MessagesState oMessagesState)
  {
   //System.Windows.Forms.MessageBox.Show(oMessagesState.MessageID.ToString());
   System.Console.WriteLine("{0},《{1}》",oMessagesState.MessageID.ToString(),oMessagesState.jMessage.Subject);
 
   //System.Console.WriteLine(oMessagesState.jMessage.Body);
   //System.Console.WriteLine(oMessagesState.jMessage.Text);

  }

  private void timer1_Tick(object sender, System.EventArgs e)
  {
   x.Execute();
  }

  private void x_MessageReceived(Microshaoft.NJMail.MessagesState oMessagesState)
  {
   if (oMessagesState.MessagesCount == 0)
   {
    //System.Windows.Forms.MessageBox.Show("game over");
   }
   else
   {
    System.Console.WriteLine(oMessagesState.MessageID.ToString());
   }
  }

  private void x_AttachmentReceive(Microshaoft.NJMail.AttachmentsState oAttachmentsState)
  {
   oAttachmentsState.FileName = "e:\\temp\\" + oAttachmentsState.FileName;
   oAttachmentsState.SaveToFile(oAttachmentsState.FileName);
   if (oAttachmentsState.Exception != null)
   {
    throw oAttachmentsState.Exception ;
   }

   oAttachmentsState.CancelCurrent = true; //不Save处理当前附件
   if (oAttachmentsState.AttachmentsCount == 0)
   {
    //System.Windows.Forms.MessageBox.Show(oAttachmentsState.MessagesState.jMessage.Attachments.Count.ToString());
   }
   else
   {
    System.Console.WriteLine(oAttachmentsState.AttachmentID.ToString());
   }
  }

  private void x_AttachmentException(Microshaoft.NJMail.AttachmentsState oAttachmentsState)
  {
   System.Console.WriteLine("Execute Exception: {0}",oAttachmentsState.Exception.Message);
   oAttachmentsState.FileName ="e:\\temp\\copy of " + oAttachmentsState.jAttachment.Name;
   //oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Retry; //上一句文件改名后重新处理
   oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Ignore; //处理下一个附件
   //oAttachmentsState.ExceptionAction = Microshaoft.NJMail.ExceptionActions.Throw;
  }
 }
}

 

时间: 2024-12-03 05:44:08

c#封装jmail的pop3收邮件的相关文章

请教:怎么解决Jmail收邮件时,中文名称的附件名称是乱码的问题

问题描述 我在用Jmail4.4pro收邮件时,如果收到的邮件是UTF8编码,会出现中文的标题.中文的附件名称都是乱码的问题.但正文.附件内容都正常.对于标题乱码,暂时找到了解决办法,不要直接用JMail.Message.Subject,而是取JMail.Message.Headers.GetHeader("Subject"),然后再解码.但对于附件名称,则没有办法处理.只能JMail.Attatchment.Name得到附件名称,但那已经是乱码,类似于"娴?璇?docx&q

利用Jmail发送和接收邮件(C#)

jmail|收邮件 using System;using jmail;using System.Collections; namespace TYM.Com.MyMail{?/// ?/// 邮件发送接收类?/// ?public class Mail?{??/// ??/// 邮件类的构造函数??/// ??public Mail()??{??} ??/// ??/// 邮件模型??/// ??public MailModel model = new MailModel();??/// ??/

认真对待 Python3 收邮件

前言 准备 初体验 试水 划水 蹚水 潜水 拓展 前言 之前老是用Python发邮件,用起来挺方便的.但是一直没实现用Python收邮件,最近忙着笔试面试,但是又不能时刻打开浏览器,刷手机看看有没有新邮件(尤其是有没有关于面试,笔试通知的邮件)啊.所以写个脚本来做下定时任务,一旦有相关的主题邮件,结合GUI控件,声音组件,给出提醒. 想来还是不错的. 封装好的客户端源码放到了我的GitHub上,有兴趣的可以下载下来试一试. https://github.com/guoruibiao/receiv

线收邮件

  一个可以在线收邮件的东东 不能收MINE的信件.可以考虑使用BASE64解码什么东东来实现.具体我忘了. 刚刚写出来的.还不是很成熟. //input.html //////////////////////////////////////////////////// <html> <head> <title>pop mail form</title> <meta http-equiv="Content-Type" content

利用JMail组件快速构建邮件程序(下)

上文<利用JMail组件快速构建邮件程序(上)>中介绍了邮件的发送,本文将介绍邮件的接收过程,示例代码运行效果图如下: 三.邮件接收篇 3.1 利用IPOP3接收邮件 接收邮件时用到的接口是IPOP3, 首先连接上邮件服务器,从Messages中得到邮件信息集合,然后就可以通过遍历集合取得每条Message中的具体内容. 请看如下代码: jmail::IPOP3Ptr pPOP3("JMail.POP3"); // 非必须,设置超时时间为60秒,默认为120秒 pPOP3-

收邮件的小程序出现了一点问题

问题描述 packagepopop;importjava.io.*;importjava.io.InputStreamReader;importjava.util.Properties;importjavax.mail.Folder;importjavax.mail.Message;importjavax.mail.Session;importjavax.mail.Store;publicclassPraseMimeMessage{publicstaticvoidmain(String[]arg

LumiSoft组件,imap、pop3收取邮件

问题描述 LumiSoft组件,imap.pop3收取邮件 基于LumiSoft组件,imap.pop3收取邮件时,邮件正文的内嵌图片如何获取,知道的朋友给个提示,困扰很久了!谢谢!

看过来:教你解决Vista无法收邮件问题

日前有个朋友买了个 预装VISTA的本本,由于工作需要使用OUTLOOK来收邮件,在VISTA上OUTLOOK升级为Windows Mail,遇到一个很奇怪的问题,当收有附件的邮件时进度条就停止在 那里,过一段时间后显示http://www.aliyun.com/zixun/aggregation/12489.html">邮件服务器连接超时,错误代码0x800CCC19. 试了很多办法都没解决,最后在一个老外的贴子上找到了解决方法,方法如下: 1.鼠标右键点开始->附件中的"

lotus能够收邮件无法发送邮件

问题描述 我司架设了一台domin服务器,有几个子公司各架设了一台服务器,ping子公司的ip可以通但trace不通,请大家帮忙了 解决方案 解决方案二:不懂,是Notes中的通信协议,没有设置好吗?解决方案三:应该是网络的问题,我原先遇到过foxmail.outlook无法发邮件但可收邮件的问题,后来通过在防火墙.路由器中放开SMTP等相应协议的收发权限后,后来就没问题了.当时也困绕了我好长时间,邮箱的设置全都没有问题,而且收邮件也没问题,就是发不了,后来才发现是网络协议发送权限没放开惹的祸!