亲宝软件园·资讯

展开

qq邮箱发送邮件 c#调用qq邮箱smtp发送邮件修改版代码分享

人气:0
想了解c#调用qq邮箱smtp发送邮件修改版代码讲解的相关内容吗,在本文为您仔细讲解qq邮箱发送邮件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:qq邮箱,smtp发送邮件,下面大家一起来学习吧。

复制代码 代码如下:

 try
            {
                MailMessage mm = new MailMessage();
                MailAddress Fromma = new MailAddress("xxxx@qq.com");
                MailAddress Toma = new MailAddress("MMMMMMM@qq.com", null);
                mm.From = Fromma;
                //收件人
                mm.To.Add("MMMMMM@qq.com");
                //邮箱标题
                mm.Subject = "Hello Dear:";
                mm.IsBodyHtml = true;
                //邮件内容
                mm.Body = "你好Mr流星!";
                //内容的编码格式
                mm.BodyEncoding = System.Text.Encoding.UTF8;
                //mm.ReplyTo = Toma;
                //mm.Sender =Fromma;
                //mm.IsBodyHtml = false;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                mm.CC.Add(Toma);
                SmtpClient sc = new SmtpClient();
                NetworkCredential nc = new NetworkCredential();
                nc.UserName = "XXXXX@qq.com";//你的邮箱地址
                nc.Password = "zzzzz";//你的邮箱密码,这里的密码是xxxxx@qq.com邮箱的密码,特别说明下~
                   sc.UseDefaultCredentials = true;
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                sc.Credentials = nc;
                //如果这里报mail from address must be same as authorization user这个错误,是你的QQ邮箱没有开启SMTP,
                //到你自己的邮箱设置一下就可以啦!在帐户下面,如果是163邮箱的话,下面该成smtp.163.com
                sc.Host = "smtp.qq.com";
                sc.Send(mm);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }


这个是我用我的2个QQ测试成功了的,有问题希望各位指正~~

加载全部内容

相关教程
猜你喜欢
用户评论