示例#1
0
    static void Example1()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create POP client.
        using (var pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            //  Connect and sign to POP server.
            pop.Connect();
            pop.Authenticate("<USERNAME>", "<PASSWORD>");

            // Read the number of currently available emails on the server.
            int count = pop.GetCount();

            Console.WriteLine(" NO. |     DATE     |          SUBJECT          ");
            Console.WriteLine("------------------------------------------------");

            // Download and receive all email messages.
            for (int number = 1; number <= count; number++)
            {
                MailMessage message = pop.GetMessage(number);

                // Read and display email's date and subject.
                Console.WriteLine($"  {number}  |  {message.Date.ToShortDateString()}  |  {message.Subject}");
            }
        }
    }
示例#2
0
        }     //end method

        public static void checkEmail()
        {
            ComponentInfo.SetLicense("FREE-LIMITED-KEY");

            using (PopClient pop = new PopClient("pop.gmail.com"))
            {
                //  Connect and sign to POP server.
                pop.Connect();
                pop.Authenticate(Ref.email, Ref.password);

                // Read the number of currently available emails on the server.
                int count = pop.GetCount();

                Console.WriteLine(" NO. |     DATE     |          MESSAGE          ");
                Console.WriteLine("------------------------------------------------");

                // Download and receive all email messages.
                try
                {
                    for (int number = 1; number <= count; number++)
                    {
                        GemBox.Email.MailMessage message = pop.GetMessage(number);

                        // Read and display email's date and subject.
                        Console.WriteLine($"  {number}  |  {message.Date.ToShortDateString()}  |  {message.BodyText}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }
示例#3
0
        public void PopTest()
        {
            using (PopClient popClient = new PopClient("pop.lsong.org"))
            {
                popClient.Connect();
                popClient.Authenticate("*****@*****.**", "lsong940");

                int messageCount = popClient.GetMessageCount();
                for (int i = messageCount; i > 0; i--)
                {
                    MessageHeader messageHeaders = popClient.GetMessageHeaders(i);
                }
            }
        }
示例#4
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            pop.Connect();
            pop.Authenticate("<USERNAME>", "<PASSWORD>");

            // Get number of available messages.
            Console.WriteLine($"Mailbox message count: {pop.GetCount()}");

            // Get size of all available messages in bytes.
            Console.WriteLine($"Mailbox size: {pop.GetSize()} Byte(s)");
        }
    }
示例#5
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            pop.Connect();
            pop.Authenticate("<USERNAME>", "<PASSWORD>");

            // Get headers for first available mail message.
            HeaderCollection headers = pop.GetHeaders(1);

            // Display message headers.
            foreach (Header header in headers)
            {
                Console.WriteLine($"{header.Name}: {header.Body}");
            }
        }
    }
示例#6
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            pop.Connect();
            pop.Authenticate("<USERNAME>", "<PASSWORD>");

            // Get information about all available messages.
            IList <PopMessageInfo> infos = pop.ListMessages();

            // Display messages information.
            foreach (PopMessageInfo info in infos)
            {
                Console.WriteLine($"{info.Number} - [{info.Uid}] - {info.Size} Byte(s)");
            }
        }
    }
示例#7
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create certificate validation delegate.
        RemoteCertificateValidationCallback validationDelegate =
            (object sender,
             X509Certificate certificate,
             X509Chain chain,
             SslPolicyErrors errors) =>
        {
            if (errors == SslPolicyErrors.None || errors == SslPolicyErrors.RemoteCertificateNameMismatch)
            {
                Console.WriteLine("Server certificate is valid.");
                return(true);
            }
            else
            {
                Console.WriteLine($"Server certificate is invalid: {errors}");
                return(false);
            }
        };

        // Create new PopClient and specify host, port, security and certificate validation callback.
        using (PopClient pop = new PopClient(
                   "<ADDRESS> (e.g. pop.gmail.com)",
                   995,
                   ConnectionSecurity.Ssl,
                   validationDelegate))
        {
            // Connect to email server.
            pop.Connect();
            Console.WriteLine("Connected.");

            // Authenticate with specified username, password and authentication mechanism.
            pop.Authenticate("<USERNAME>", "<PASSWORD>", PopAuthentication.Plain);
            Console.WriteLine("Authenticated.");
        }
    }
示例#8
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create new POP client.
        using (var pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            // By default the connect timeout is 5 sec.
            pop.ConnectTimeout = TimeSpan.FromSeconds(4);

            // Connect to POP server.
            pop.Connect();
            Console.WriteLine("Connected.");

            // Authenticate using the credentials; username and password.
            pop.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");
        }

        Console.WriteLine("Disconnected.");
    }
示例#9
0
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (PopClient pop = new PopClient("<ADDRESS> (e.g. pop.gmail.com)"))
        {
            // Connect and login.
            pop.Connect();
            Console.WriteLine("Connected.");

            pop.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");

            // Check if there are any messages available on the server.
            if (pop.GetCount() == 0)
            {
                return;
            }

            // Download message with sequence number 1 (the first message).
            MailMessage message = pop.GetMessage(1);

            // Display message sender and subject.
            Console.WriteLine();
            Console.WriteLine($"From: {message.From}");
            Console.WriteLine($"Subject: {message.Subject}");

            // Display message body.
            Console.WriteLine("Body:");
            string body = string.IsNullOrEmpty(message.BodyHtml) ?
                          message.BodyText :
                          message.BodyHtml;
            Console.WriteLine(body);
        }
    }
示例#10
0
        public void MailTest()
        {
            using (SmtpClient smtpClient = new SmtpClient("smtp.163.com"))
            {
                smtpClient.Connected              += (x, y) => _logger.Debug("mail", "Connected:{0}", y);
                smtpClient.Authenticated          += (x, y) => _logger.Debug("mail", "Authenticated:{0}", y);
                smtpClient.StartedMessageTransfer += (x, y) => _logger.Debug("mail", "StartedMessageTransfer:{0}", y);
                smtpClient.EndedMessageTransfer   += (x, y) => _logger.Debug("mail", "EndedMessageTransfer:{0}", y);
                smtpClient.Disconnected           += (x, y) => _logger.Debug("mail", "Disconnected:{0}", y);

                smtpClient.Connect();

                smtpClient.UserName = "******";
                smtpClient.Password = "******";

                smtpClient.Authenticate("*****@*****.**", "*****@*****.**");

                MailAddress from = new MailAddress("Lsong", "*****@*****.**");
                MailAddress to   = new MailAddress("*****@*****.**");
                MailAddress cc   = new MailAddress("Test<*****@*****.**>");

                MailMessage mailMessage = new MailMessage(from, to);
                mailMessage.AddRecipient(cc, AddressType.Cc);
                mailMessage.AddRecipient("*****@*****.**", AddressType.Bcc);

                mailMessage.Charset      = "UTF-8";
                mailMessage.Priority     = MailPriority.High;
                mailMessage.Notification = true;

                mailMessage.AddCustomHeader("X-CustomHeader", "Value");
                mailMessage.AddCustomHeader("X-CompanyName", "Value");

                //string testCid = mailMessage.AddImage("C:\\test.bmp");

                //mailMessage.AddAttachment("C:\\test.zip");

                mailMessage.Subject  = "This's a test Mail.";
                mailMessage.Body     = "hello everybody .";
                mailMessage.HtmlBody =
                    string.Format("<html><body>hello everybody .<br /><img src='cid:{0}' /></body></html>", "");

                smtpClient.SendMail(mailMessage);
            }

            using (PopClient popClient = new PopClient("pop.163.com"))
            {
                popClient.UserName = "";
                popClient.Password = "";
                popClient.Connect("pop.163.com", 110, false);
                popClient.Authenticate("*****@*****.**", "*****@*****.**");

                int messageCount = popClient.GetMessageCount();
                for (int i = messageCount; i > 1; i--)
                {
                    //try
                    //{
                    MessageHeader      messageHeader = popClient.GetMessageHeaders(i);
                    MailAddress        sender        = messageHeader.Sender;
                    MailAddress        from          = messageHeader.From;
                    List <MailAddress> to            = messageHeader.To;
                    string             subject       = messageHeader.Subject;

                    _logger.Debug("mail", subject);
                    if (sender != null)
                    {
                        _logger.Info("mail", "Sender:{0}", sender);
                    }
                    if (from != null)
                    {
                        _logger.Info("mail", "From:{0}", from);
                    }
                    if (to != null)
                    {
                        foreach (MailAddress mailAddress in to)
                        {
                            _logger.Info("mail", "TO:{0}", mailAddress);
                        }
                    }
                    Message     message  = popClient.GetMessage(i);
                    MessagePart textBody = message.FindFirstPlainTextVersion();
                    MessagePart htmlBody = message.FindFirstHtmlVersion();


                    if (textBody != null)
                    {
                        string text = textBody.GetBodyAsText();
                        System.Console.WriteLine(text);
                    }
                    else if (htmlBody != null)
                    {
                        string html = htmlBody.GetBodyAsText();
                        System.Console.WriteLine(html);
                    }
                    System.Console.ReadKey();
                    //}
                    //catch (Exception exception)
                    //{
                    //    _logger.Error("mail", exception);
                    //}
                }
            }
        }