首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

使用.Net自带的邮件类发送邮件报错误

2013-10-24 
使用.Net自带的邮件类发送邮件报异常本帖最后由 bobo3358 于 2013-10-21 14:00:36 编辑写了一个发送邮件的

使用.Net自带的邮件类发送邮件报异常
本帖最后由 bobo3358 于 2013-10-21 14:00:36 编辑 写了一个发送邮件的小程序,之前 一直都可以发送邮件的,今天突然不能发送了,调试了一下发现报异常: InnerException:调用的目标发生异常,求助各位大侠;


using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Configuration;

namespace WindowsFormsApplication1
{
    public class Mail
    {
        public static bool Send(string to, string title, string content, bool MailServerBodyHtml)
        {           
                try
                {
                    System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
                    message.To = to;
                    message.From = "1197312019@qq.com";
                    message.Subject = title;
                    message.BodyFormat = System.Web.Mail.MailFormat.Html;
                    message.BodyEncoding = Encoding.UTF8;
                    message.Body = content;
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication 
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "********@qq.com"); //set your username here 
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "*******"); //set your password here 
                    //if (Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"].ToString()) != 25)
                    //{
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 465);//465
                    message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
                    //}

                    System.Web.Mail.SmtpMail.SmtpServer = "smtp@qq.com";//"smtp.qq.com";
                    System.Web.Mail.SmtpMail.Send(message);
                    return true;
                }
                catch (Exception ex)
                {

                    
                    return false;
                }            
        }
    }
}



 private void button1_Click(object sender, EventArgs e)
        {
           if(Mail.Send("1197312019@qq.com","aaa","aaaa",true)
            {
                MessageBox.Show("aaaaaaa");
            }
            else


            {
                MessageBox.Show("bnnnnnnnnnn");
            }
        }


[解决办法]
qq好像已经不支持了。
[解决办法]
引用:
Quote: 引用:

qq好像已经不支持了。

换成新浪也是一样

新浪早就不支持了

热点排行