欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-02-23 22:08:40
复制代码 代码如下: try           ...

复制代码 代码如下:

 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测试成功了的,有问题希望各位指正~~