c USES S22.Imap to receive swordling activation code email code sample of imap to receive email

  • 2020-05-30 21:00:30
  • OfStack


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# using IMAP email 
 */
        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"));
      //  You can also use other criteria to retrieve your mail 
               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(" There's no mail you're looking for ");
                }
                imap.Dispose();
            }
            catch (InvalidCredentialsException)
            {
                MessageBox.Show(" The server refused to connect, the password may be wrong! ");
                imap.Dispose();
            }
        }
    }
}


Related articles: