c#发送邮件未实现该方法或操作
publicvoidbtn_Send_Click(objectsender,EventArgse){//创建MailMessage对象MailAddressfrom=ne...
public void btn_Send_Click(object sender, EventArgs e)
{
//创建MailMessage对象
MailAddress from = new MailAddress("731815767@qq.com");
MailAddress to = new MailAddress("vincent@discosha.com");
MailMessage mailMessage = new MailMessage(from, to) ;
mailMessage.Subject="主题";
mailMessage.Body="这是一封来自远方的邮件.";
// Attachment attachment01 = new Attachment("E:\\01.jpg"); //附件
// Attachment attachment02 = new Attachment("E:\\02.mp3");
// mailMessage.Attachments.Add(attachment01);
//mailMessage.Attachments.Add(attachment02);
//创建SmtpClient对象 邮箱服务器smtp.163.com
SmtpClient smtpClient = new SmtpClient("smtp.qq.com");
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials =
new NetworkCredential("731815767@qq.com", "123456"); //邮箱认证登录
//smtpClient.Timeout = 5000;
try
{
//使用异步发送,不会阻塞该线程
smtpClient.SendCompleted += new //完成发送调用回调函数
SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendAsync(mailMessage, mailMessage);
}
catch(Exception ex)
{
mailMessage.Dispose(); //主动释放资源
smtpClient.Dispose();
MessageBox.Show("发送失败! "+System.Environment.NewLine+
"错误信息:"+ ex.Message);
}
return;
}
private void SendCompletedCallback(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
throw new NotImplementedException();
}
internal void btn_Send_Click()
{
throw new NotImplementedException();
}
感觉逻辑什么的没问题,但是就是报错
未实现该方法或操作。 展开
{
//创建MailMessage对象
MailAddress from = new MailAddress("731815767@qq.com");
MailAddress to = new MailAddress("vincent@discosha.com");
MailMessage mailMessage = new MailMessage(from, to) ;
mailMessage.Subject="主题";
mailMessage.Body="这是一封来自远方的邮件.";
// Attachment attachment01 = new Attachment("E:\\01.jpg"); //附件
// Attachment attachment02 = new Attachment("E:\\02.mp3");
// mailMessage.Attachments.Add(attachment01);
//mailMessage.Attachments.Add(attachment02);
//创建SmtpClient对象 邮箱服务器smtp.163.com
SmtpClient smtpClient = new SmtpClient("smtp.qq.com");
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials =
new NetworkCredential("731815767@qq.com", "123456"); //邮箱认证登录
//smtpClient.Timeout = 5000;
try
{
//使用异步发送,不会阻塞该线程
smtpClient.SendCompleted += new //完成发送调用回调函数
SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendAsync(mailMessage, mailMessage);
}
catch(Exception ex)
{
mailMessage.Dispose(); //主动释放资源
smtpClient.Dispose();
MessageBox.Show("发送失败! "+System.Environment.NewLine+
"错误信息:"+ ex.Message);
}
return;
}
private void SendCompletedCallback(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
throw new NotImplementedException();
}
internal void btn_Send_Click()
{
throw new NotImplementedException();
}
感觉逻辑什么的没问题,但是就是报错
未实现该方法或操作。 展开
1个回答
展开全部
要把throw new NotImplementedException();去掉
代码:
public void btn_Send_Click(object sender, EventArgs e)
{
MailAddress from = new MailAddress("123456@qq.com");
MailAddress to = new MailAddress("456789@qq.com");
MailMessage mailMessage = new MailMessage(from, to);
mailMessage.Subject = "主题";
mailMessage.Body = "封自远邮件.";
//Attachment attachment01 = new Attachment("E:\\01.jpg"); //附件
//Attachment attachment02 = new Attachment("E:\\02.mp3");
//mailMessage.Attachments.Add(attachment01);
//mailMessage.Attachments.Add(attachment02);
//创建SmtpClient象 邮箱服务器smtp.163.com
SmtpClient smtpClient = new SmtpClient("smtp.qq.com");
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new NetworkCredential("123456@qq.com", "000000"); //邮箱认证登录
try
{
//使用异步发送,阻塞该线程
smtpClient.SendCompleted += new //完发送调用调函数
SendCompletedEventHandler(SendCompletedCallback);
smtpClient.SendAsync(mailMessage, mailMessage);
}
catch (Exception ex)
{
mailMessage.Dispose(); //主释放资源
smtpClient.Dispose();
MessageBox.Show("发送失败! " + System.Environment.NewLine +
"错误信息:" + ex.Message);
}
}
private void SendCompletedCallback(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
// 留空
}
更多追问追答
追问
但是这么执行了,也没进catch,但是就是邮件没有发送。
追答
额,我自己试过了,我自己收到了,你看看有没有写错密码什么的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询