如何用qq代理发送邮件

如何用qq代理发送邮件

      今天我想写一篇服务器发送验证邮件的的文章,我查阅过其他博客里面写的文章,都是可以实现的,但是对于初学者来说是一个很痛苦的事情,很多代码看不懂,原因有多种,写的多,写的乱,然后就不想往下看了。我今天详细的为大家写一下该如何去实现这个功能。

     1.要准备两个qq邮箱,一个用于发送验证邮件,一个用于接收测试邮件。我先准备了两个。

     2.发送验证的qq邮箱必须开通IMAP/SMTP服务服务。

        (1).打开qq邮箱=》设置=》账户=》开启服务然后获得授权码,记住授权码。

          

     3.本人用MVC进行了简单的测试。

      

   /// <summary>
        /// 代理服务器
        /// 如qq,163等
        /// </summary>
        /// <summary>发送的邮箱</summary>
        /// <summary>授权码qq邮箱获得的</summary>
        /// <summary>接收的邮箱</summary>
        /// <summary>标题</summary>
        /// <summary>邮件</summary>
        /// <returns></returns>
        public void SendSMTPEMail(string strSmtpServer, string strFrom, 
            string strFromPass, string strto, string strSubject, string strBody)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.EnableSsl = true;
            client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            System.Net.Mail.MailMessage message = new MailMessage(strFrom, strto, strSubject, strBody);
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;

            //使用文件路径发送附件
            //AlternateView item = new AlternateView(@"D:\\软件\\(软电话)eyebeam1.5.rar", "application/x-rar-compressed");
            //message.AlternateViews.Add(item);
            //message.AlternateViews.Dispose();

            //使用Stream发送附件 
            //Attachment letter = new Attachment(FileUploadLetter.FileContent, FileUploadLetter.PostedFile.ContentType);
            //letter.ContentDisposition.Inline = true;
            //letter.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
            ////inline.ContentId = "1";
            //letter.ContentType.MediaType = FileUploadLetter.PostedFile.ContentType;
            //letter.ContentType.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
            //letter.Name = Path.GetFileName(FileUploadLetter.PostedFile.FileName);
            //message.Attachments.Add(letter);
            //message.Attachments.Dispose();

            client.Send(message);
        }
    }
View Code

  这是一个发送邮件的函数,你可以将它放在一个类中或者直接调用

  4.调用函数时传参成功即可发送邮件。

  5.不理解的可以留言。

         
posted @ 2016-12-17 19:48 冰叔博客 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值