C# winform 通过调用outlook发送邮件

//用vs2005,只需要加一个com组件,名称是:Microsoft outlook 11.0 object library 

using System.Net.Mail;

 /// <summary>

  /// 发送邮件的方法

  /// </summary>

  /// <param name="strSender">发件人邮箱地址</param>

 /// <param name="strPass">发件人邮箱密码</param>

/// <param name="Toer">收件人邮箱地址</param>

 public void MailMessage(string strSender, string strPass, string Toer)

 {

 try

{  MailAddress from = new MailAddress(strSender, "发件人的名称");//发件人邮箱地址

  MailAddress to = new MailAddress(Toer, "收件人的名称");//收件人邮箱地址

MailMessage mailMsg = new MailMessage(from, to);

mailMsg.Body = "我成功了! "; //所要发送的文本

mailMsg.Subject = "你好";//邮箱标题

SmtpClient client = new SmtpClient("smtp.163.com");//smtp服务器地址

// Include credentials if the server requires them.

client.Credentials = CredentialCache.DefaultNetworkCredentials;

client.Send(mailMsg);

MessageBox.Show("OK");

} catch (System.Exception ex)

 { MessageBox.Show("Error!"); }  

}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页