Net Core教程

C# 使用网易126邮箱发件和收件

本文主要是介绍C# 使用网易126邮箱发件和收件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.发件

  System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Host = "smtp.126.com";//使用163的SMTP服务器发送邮件
                client.UseDefaultCredentials = true;
                client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                //*******为自己密码或授权码
                client.Credentials = new System.Net.NetworkCredential("shihao316558512", "*******");
                System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
                Message.From = new System.Net.Mail.MailAddress("shihao316558512@126.com");
                Message.To.Add("316558512@qq.com");//将邮件发送给QQ邮箱
                Message.Subject = "测试标体";
                Message.Body = "测试邮件体";
                Message.SubjectEncoding = System.Text.Encoding.UTF8;
                Message.BodyEncoding = System.Text.Encoding.UTF8;
                Message.Priority = System.Net.Mail.MailPriority.High;
                Message.IsBodyHtml = true;
                client.Send(Message);

2.收件

    using (Pop3Client client = new Pop3Client())
                {
                    client.Connect("pop.126.com", 110, false);

                    //账号,*******为密码或者授权码,认证方式
                    client.Authenticate("shihao316558512", "**********", AuthenticationMethod.Auto);  //登录认证

                    int count = client.GetMessageCount(); //获取邮箱总数
                    int size = client.GetMessageSize(1);  //获取编号为1的邮件的大小
                    OpenPop.Mime.Message msg = client.GetMessage(1);                    //获取编号为1的邮件的内容
                    string title = msg.Headers.Subject;
                    //client.DeleteMessage(1);      //标记编号为1的邮件为"删除"
                    //...
                }

 

这篇关于C# 使用网易126邮箱发件和收件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!