c#中如何實現發送郵件功能 剛開始學習c#,有個問題問下前輩們,c#中如何實現發送郵件功能呢?找了好多例子調試不成功,請幫幫忙,感謝! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以了解下SMTP协议! 还有这个命名空间using System.Threading; using System.Net.Mail;(命名空间)<http://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient%28v=VS.80%29.aspx> MailMessage mainMsg = new MailMessage(); mainMsg.Body ="要发送的消息"; mainMsg.Subject = "主题"; mainMsg.From = new MailAddress("发送者邮箱","发送者昵称", Encoding.UTF8);//("[email protected]", "397324300", Encoding.UTF8); mainMsg.To.Add("添加收件人邮箱地址"); //("[email protected]"); SmtpClient client = new SmtpClient(); client.Host ="smtp.qq.com"; client.Credentials = new System.Net.NetworkCredential("发送者邮箱登录名", "发送者邮箱密码");//("[email protected]", "123456"); object obj = mainMsg; client.SendAsync(mainMsg, obj); using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net.Mail;//(命名空间)<http://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient%28v=VS.80%29.aspx> namespace ConsoleApplication1{ public class EmailSend { public void Send() { try { MailMessage mainMsg = new MailMessage(); mainMsg.Body = "bendan"; mainMsg.Subject = "bendan"; mainMsg.From = new MailAddress("[email protected]", "昵称", Encoding.UTF8);//("[email protected]", "397324300", Encoding.UTF8); mainMsg.To.Add("[email protected]");//收件人地址 //("[email protected]"); SmtpClient client = new SmtpClient(); client.Host = "smtp.163.com";//如QQ 把 163 改成QQ client.Credentials = new System.Net.NetworkCredential("帐号", "密码");//("[email protected]", "123456"); object obj = mainMsg; client.SendAsync(mainMsg, obj); } catch(Exception e) { Console.WriteLine(e.ToString()); } } }} http://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient%28v=VS.80%29.aspx要不你再参考下这个地址关于这个类的使用 JMail.Net/系统自带的System.Net.Mail都可以,要是用JMail.Net的话自己修改一下源代码还可以实现快速多封连发 js问题,求解 waitone占用cpu时间吗 求助,关于字符串操作的 我要判断一个单元格里面的内容有没有12位,如果有的话发生事件? 如何判断exe已经运行,如已运行如何将其当前运行窗体显示到最前面? 求生成随机书的代码 C#从串口接收到的三组不同的数据分别在三个文本框中显示 C#中怎么用代码控制播放视频文件? 日期Calendar控件中,怎样设置使取出的日期为yyyy-mm-dd格式? .net 4.5下winform配置文件保存不了 多串口通信的问题 关于C#的几个问题
还有这个命名空间using System.Threading;
mainMsg.Body ="要发送的消息";
mainMsg.Subject = "主题";
mainMsg.From = new MailAddress("发送者邮箱","发送者昵称", Encoding.UTF8);//("[email protected]", "397324300", Encoding.UTF8);
mainMsg.To.Add("添加收件人邮箱地址");
//("[email protected]");
SmtpClient client = new SmtpClient();
client.Host ="smtp.qq.com";
client.Credentials = new System.Net.NetworkCredential("发送者邮箱登录名", "发送者邮箱密码");//("[email protected]", "123456");
object obj = mainMsg;
client.SendAsync(mainMsg, obj);
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;//(命名空间)<http://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient%28v=VS.80%29.aspx>
namespace ConsoleApplication1
{
public class EmailSend
{
public void Send()
{
try
{
MailMessage mainMsg = new MailMessage();
mainMsg.Body = "bendan";
mainMsg.Subject = "bendan";
mainMsg.From = new MailAddress("[email protected]", "昵称", Encoding.UTF8);//("[email protected]", "397324300", Encoding.UTF8);
mainMsg.To.Add("[email protected]");//收件人地址
//("[email protected]");
SmtpClient client = new SmtpClient();
client.Host = "smtp.163.com";//如QQ 把 163 改成QQ
client.Credentials = new System.Net.NetworkCredential("帐号", "密码");//("[email protected]", "123456");
object obj = mainMsg;
client.SendAsync(mainMsg, obj);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
要不你再参考下这个地址
关于这个类的使用