- #5楼 得分:18回复于:2008-10-06 18:28:17C# code
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Net.Mail;
- using System.Net;
- /// <summary>
- /// Mail 的摘要说明
- /// </summary>
- public class Mail
- {
- public Mail()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- /// <summary>
- /// 发送邮件
- /// </summary>
- /// <param name="MailFrom">发件人的地址,例如: anybody@sohu.com</param>
- /// <param name="MailTo">收件人的地址例如: Toanybody@sohu.com</param>
- /// <param name="subject">发送邮件的主题</param>
- /// <param name="body">发送邮件的正文</param>
- /// <param name="host">STMT主机的名称或IP地址</param>
- /// <param name="userName">与STMT主机凭据关联的用户名</param>
- /// <param name="userPwd">与STMT主机凭据关联的密码</param>
- /// <returns>返回是否成功</returns>
- public bool SendMail(string MailFrom, string MailTo, string subject, string body, string host, string userName, string userPwd)
- {
- //string sReturn = string.Empty;
- //string MailFrom = "tiancaixgd@sohu.com";
- //string MailTo = "tiancaixgd@sohu.com";
- //string subject = "主题";
- //string body = "正文";
- //string host = "smtp.sohu.com";
- //string userName = "tiancaixgd";
- //string userPwd = "7736006";
- System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage(MailFrom, MailTo, subject, body);
- mailMsg.IsBodyHtml = false;
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(host, 25);
- NetworkCredential NC = new NetworkCredential(userName, userPwd);
- smtp.Credentials = NC;
- smtp.Timeout = 20*1000;
- try
- {
- smtp.Send(mailMsg);
- return true;
- }
- catch (Exception ee)
- {
- throw ee;
- }
- }
- /// <summary>
- /// 发送邮件
- /// </summary>
- /// <param name="MailFrom">发件人的地址,例如: anybody@sohu.com</param>
- /// <param name="MailTo">收件人的地址例如: Toanybody@sohu.com</param>
- /// <param name="subject">发送邮件的主题</param>
- /// <param name="body">发送邮件的正文</param>
- /// <param name="host">STMT主机的名称或IP地址</param>
- /// <param name="userName">与STMT主机凭据关联的用户名</param>
- /// <param name="userPwd">与STMT主机凭据关联的密码</param>
- /// <param name="port">STMT的端口号</param>
- /// <returns>返回是否成功</returns>
- public bool SendMail(string MailFrom, string MailTo, string subject, string body, string host, string userName, string userPwd,int port)
- {
- //string sReturn = string.Empty;
- //string MailFrom = "tiancaixgd@sohu.com";
- //string MailTo = "tiancaixgd@sohu.com";
- //string subject = "主题";
- //string body = "正文";
- //string host = "smtp.sohu.com";
- //string userName = "tiancaixgd";
- //string userPwd = "7736006";
- System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage(MailFrom, MailTo, subject, body);
- mailMsg.IsBodyHtml = false;
- System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(host, port);
- NetworkCredential NC = new NetworkCredential(userName, userPwd);
- smtp.Credentials = NC;
- smtp.Timeout = 20 * 1000;
- try
- {
- smtp.Send(mailMsg);
- return true;
- }
- catch (Exception ee)
- {
- throw ee;
- }
- }
- }