using System;
using System.Text;
using System.Net.Mail;
using System.Net;
using NingQHai.Tools;
namespace NingQHai.Web {
/// <summary>
/// 邮件操作实体类
/// </summary>
public class myMail {
String _title = "";
String _body = "";
String _host = "";
String _pwd = "";
String _uName = "";
String _accept = "";
/// <summary>
/// 接收邮件地址
/// </summary>
public String Accept
{
get { return _accept; }
set { _accept = value; }
}
/// <summary>
/// 发送邮件的用户名
/// </summary>
public String UName
{
get { return _uName; }
set { _uName = value; }
}
/// <summary>
/// 发送邮件的密码
/// </summary>
public String Pwd
{
get { return _pwd; }
set { _pwd = value; }
}
/// <summary>
/// 邮件服务器的地址IP或域名
/// </summary>
public String Host
{
get { return _host; }
set { _host = value; }
}
/// <summary>
/// 邮件内容
/// </summary>
public String Body
{
get { return _body; }
set { _body = value; }
}
/// <summary>
/// 邮件标题
/// </summary>
public String Title
{
get { return _title; }
set { _title = value; }
}
/// <summary>
/// 实例化邮件实体类
/// </summary>
public myMail()
{
}
/// <summary>
/// 邮件实体类
/// </summary>
/// <param name="uName">发送邮件的用户名</param>
/// <param name="pwd">相应的密码</param>
/// <param name="accept">接收的EMail</param>
/// <param name="host">发邮件的主机</param>
/// <param name="title">邮件标题</param>
/// <param name="body">邮件内容</param>
public myMail(String uName,String pwd,String accept,String host,String title,String body)
{
this.UName = uName; this.Pwd = pwd; this.Accept = accept;
this.Title = title; this.Body = body; this.Host = host;
}
/// <summary>
/// 发送邮件
/// </summary>
/// <returns></returns>
public Boolean sendMail()
{
Boolean flag = false;
try {
SmtpClient client = new SmtpClient(this.Host);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(this.UName, this.Pwd);
/*指定如何处理待发的邮件*/
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage message = new MailMessage(this.UName, this.Accept, this.Title, this.Body);
message.From = new MailAddress(this.UName);
String[] txtUsers = this.Accept.Split(',');
foreach (String str in txtUsers)
{
if (str != null & str != String.Empty)
{
message.To.Add(str);
}
}
message.Subject = this.Title;
message.Body = this.Body;
message.BodyEncoding = Encoding.Default;
message.Priority = MailPriority.High;
message.IsBodyHtml = true;
client.Send(message);
flag = true;
}
catch (Exception ex) {
Err.ErrString = ex.Message;
}
return flag;
}
}
}