MailMessage无法正常工作我不知道自己错过了什么。如果缺少代码或我使用了错误的命名空间,请更正我的程序吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Web.Mail;
using System.Data.SqlClient;
using System.Data;
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
SmtpClient smtp=new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials=new NetworkCredential(txtemail.Text,txtpassword.Text);
MailMessage mail = new MailMessage(txtemail.Text, ddlemail.Text, txtsubject.Text, txtbody.Text);
smtp.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}
}
答案 0 :(得分:2)
问题是因为你引用了
using System.Net.Mail;
using System.Web.Mail;
因此System.Web.Mail.MailMessage
和System.Net.Mail.MailMessage
删除using System.Web.Mail;
参考