用C#写代码实现邮件发送的效果
解决方案 »
- 类中的结构体集合无法赋值的问题
- .net remoting,如果服务器在局域网,客户端如何连接,help...
- 如何获得dataset.datatable表中对应字段的最大、最小值(即如何在断开的表中应用SQL语句)?
- 高分求C#写的OpenGL方面的例程,或网址也行
- 如何将grid的模板表头的HeaderText显示出来
- 如何读取一个txt就删除刚刚读取的txt
- caozhy bdmh版主请指导 C#读取串口发送接收命令帧 谢谢
- 询问关于如何同步session的问题(ws和aspx)
- 我要在datagrid控件中通过双击某一单元框,来取得当前框的内容???
- 一个Process的问题!
- Windows中的Tag属性
- 路径问题
using System.Net; MailAddress MailFrom = new MailAddress("*****@163.com");
MailAddress MailTo = new MailAddress("*****@gmail.com");
MailMessage Mails = new MailMessage(MailFrom, MailTo);
Mails.Subject = "Kevin Test Mail";
Mails.IsBodyHtml = true;
Mails.Body = " this is a test mail whitch used the Net2.0";
Attachment AFile = new Attachment(@"C:\MyLog.txt");
Mails.Attachments.Add(AFile);
SmtpClient Smtps = new SmtpClient("smtp.163.com");
Smtps.Credentials = new NetworkCredential("****","****");
try
{
Smtps.Send(Mails);
MessageBox.Show("发送成功");
}
catch (Exception ex)
{
MessageBox.Show("发送出错,错误信息如下:" + ex.Message);
}
/// <summary>
/// 发送邮件
/// </summary>
internal void Send()
{
System.Web.Mail.MailMessage mailmessage = new MailMessage(); mailmessage.From = "[email protected]";
mailmessage.To = "张大伟";
mailmessage.Subject = "我是主题";
mailmessage.Body = "我是内容";
mailmessage.Cc = "张明";
mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mailmessage.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusername",myEmailUserName);
//自己邮箱的用户名
mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", myEmailPassword);
//自己邮箱的密码
System.Web.Mail.SmtpMail.SmtpServer ="smtp.163.com"; //SMTP Server
System.Web.Mail.SmtpMail.Send(mailmessage); }