欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#使用S22.Imap收剑灵激活码邮件代码示例(imap收邮件)

程序员文章站 2024-02-18 23:45:52
复制代码 代码如下:using system;using system.collections.generic;using system.componentmodel;us...

复制代码 代码如下:

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using s22.imap;

namespace _163pop3
{
    public partial class form1 : form
    {
        public form1()
        {
            initializecomponent();
        }

        private void form1_load(object sender, eventargs e)
        {

        }
        /*
 * 
 *  by im0khu 
 *  c#利用imap收邮件
 */
        private void btnfetch_click(object sender, eventargs e)
        {

            string imapserver = "imap.163.com";
            string imapuserame = "xiagegou_com";
            string imappwd = "password2013";
            imapclient imap = new imapclient(imapserver, 993, true);

            try
            {
                imap.login(imapuserame, imappwd, authmethod.login);
                uint[] uids = imap.search(searchcondition.subject("this's a test email"));
               // uint[] uids = imap.search(searchcondition.from("ssss@oschina.net"));
      // 也可以使用通过其它条件进行检索你的邮件
               if (uids.length > 0)
                {
                    system.net.mail.mailmessage msg = imap.getmessage(uids[0]);
                    emaillst.items.add("subject: " + msg.subject);
                    emailbody.text = msg.body;                  

                }
                else
                {
                    emaillst.items.add("没有你要找的邮件");
                }
                imap.dispose();

            }
            catch (invalidcredentialsexception)
            {
                messagebox.show("服务器拒绝连接,可能密码错误!");
                imap.dispose();
            }
        }
    }
}