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>
/// SendMail 的摘要描述
/// </summary>
public class SendMail
{
/// <summary>
/// 通过网络发送到Smtp服务器在进行转发 发送邮件[ 需要用户名与密码,还需要服务器支持web smtp方式发送 如2007年以前注册的163的邮箱 ]
/// -- snail 2009-4-23
/// </summary>
/// <param name="from">发邮件的人的邮件地址</param>mail.jadever.com.cn
/// <param name="to">收邮件的人的邮件地址</param>
/// <param name="title">经过 System.Web.HttpContext.Current.Server.HtmlEncode(title) 编码过的 邮件标题</param>
/// <param name="body">经过 System.Web.HttpContext.Current.Server.HtmlEncode(title) 编码过的 邮件主题内容,支持Html</param>
/// <param name="smtp">发送邮件的Smtp服务器</param>
/// <param name="port">发送邮件的Smtp服务器的端口号,一般为25</param>
/// <param name="user">发送邮件使用的用户名</param>
/// <param name="pwd">发送邮件使用的密码</param>
/// <returns>发送成功返回true</returns>
public Boolean Send(String from,String to, String title,String body,String smtp,String port,String user,String pwd)
{
try
{
MailAddress mfrom = new MailAddress(from);
MailAddress mto = new MailAddress(to);
MailMessage message = new MailMessage(mfrom, mto);
message.IsBodyHtml = true;
message.Subject = System.Web.HttpContext.Current.Server.HtmlDecode(title);
message.Body = System.Web.HttpContext.Current.Server.HtmlDecode(body);
message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient(smtp, Convert.ToInt32(port));
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(user, pwd);
|