zoukankan      html  css  js  c++  java
  • c#QQ邮件编程学习(收发邮件)

    本次c#实现邮件管理编程的目的是实现第三方邮件管理,邮箱基于QQ邮箱,发送邮件直接采用.NET自带的System.Net.Mail类,接收邮件采用第三方组件Lumisoft.Net。现将基本实现的接收邮件和发送邮件代码记录如下。

    1.发送邮件:基于System.Net.Mail。

    using System.Net.Mail;
      public void SendMail(string MailFrom, string MailTo, string MailPwd, string Mailtitle,string MailCon,string attachMentUrl)
            {
                SmtpClient client = new SmtpClient("smtp.qq.com");
                client.EnableSsl = true;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential(MailTo + "@qq.com", MailPwd);
    
                MailAddress From = new MailAddress(MailFrom + "@qq.com", "fxy", Encoding.UTF8);
                MailAddress To = new MailAddress(MailTo + "@qq.com", "", Encoding.UTF8);
    
                MailMessage myMessage = new MailMessage(From,To);
                myMessage.Body = MailCon;
                myMessage.BodyEncoding = Encoding.UTF8;
                myMessage.Subject = Mailtitle;
                myMessage.SubjectEncoding = Encoding.UTF8;
                myMessage.IsBodyHtml = true;
    
                Attachment attachment = new Attachment(attachMentUrl);
                myMessage.Attachments.Add(attachment);
    
                try
                {
                    client.Send(myMessage);
                }
                catch (InvalidOperationException e)
                { }
                catch (Exception e)
                { }
                finally
                {
                    Console.ReadLine();
                }
            }

    2.接收邮件:基于Lumisoft.Net(

    using LumiSoft.Net.POP3.Client;
    using LumiSoft.Net.Mail;
     public void GetEmails()
            {
                using (POP3_Client c = new POP3_Client())
                {
                    c.Connect("pop.qq.com", 995, true);
                    c.Login("1300837979@qq.com", "sjgqkszeqlcqgihc");
                    if (c.Messages.Count > 0)
                    {
                        for (var i = 0; i < c.Messages.Count; i++)
                        {
                            var t = Mail_Message.ParseFromByte(c.Messages[i].MessageToByte());
                            var from = t.From;
                            var to=t.To;
                            var date = t.Date;
                            var subject = t.Subject;
                            var bodyText=t.BodyText;
                        }
                        
                    }
                }
            }
  • 相关阅读:
    Oracle中的exist和in
    oracle恢复误删数据
    【axios】API 说明
    Content-type对照表
    【gdal】创建GeoTiff栅格数据
    NPM使用
    【nodejs】request 和 response 对象
    【nodejs】express框架+mysql后台数据查询
    webapp网络定位
    JS对象创建的几种方法
  • 原文地址:https://www.cnblogs.com/fuxuyang/p/7374476.html
Copyright © 2011-2022 走看看