From -- 发送邮件的地址
To -- 接受邮件的地址
Subject -- 邮件的标题
Priority -- 邮件的优先级(有效值为High,Low,Normal)
Attachments -- 返回一个集合,代表附件
Bcc -- 密送地址
Cc -- 抄送地址
Body -- 获取或是设置电子邮件消息的内容
BodyFormat -- 获取或是设置MailFormat的枚举值,此值指定消息体邮件的格式(Html格式、Text格式)
Bodyencoding -- 指定消息的编码方式编码(主要有Base64,UUencode)
UrlContentBase :在HTML格式邮件中的
url编码方式
UrlContentLocation:邮件信息的优先级(High, Medium,Low)
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;
using System.Net.Mail;
using System.Text;
public class
sendmail
...{
public SendMail()
...{
}
private string _host;
/**//// <summary>
/// 服务器地址
/// </summary>
public string Host
...{
get ...{ return _host; }
set ...{ _host = value; }
}
private int _port;
/**//// <summary>
/// 服务器端口
/// </summary>
public int Port
...{
get ...{ return _port; }
set ...{ _port = value; }
}
private string _smtpUsername;
/**//// <summary>
/// 发送人邮箱用户名
/// </summary>
public string SmtpUsername
...{
get ...{ return _smtpUsername; }
set ...{ _smtpUsername = value; }
}
private string _sendemail;
/**//// <summary>
/// 发送人邮箱帐号(只接收加密串,发邮件时解密)
/// </summary>
public string SendEmail
...{
get
...{
return _sendemail;
}
set ...{ _sendemail = value; }
}
private string _replyToEmail;
/**//// <summary>
/// 回复人邮箱账号
/// </summary>
public string ReplyToEmail
...{
get ...{ return _replyToEmail; }
set ...{ _replyToEmail = value; }
}
private string _replyUserName;
/**//// <summary>
/// 回复人用户名
/// </summary>
public string ReplyUserName
...{
get ...{ return _replyUserName; }
set ...{ _replyUserName = value; }
}
private string _getemail;
/**//// <summary>
/// 收件人邮箱帐号
/// </summary>
public string GetEmail
...{
get ...{ return _getemail; }
set ...{ _getemail = value; }
}
private string _smtpPassword;
/**//// <summary>
/// 发送人邮箱密码(只接收加密串,发邮件时解密)
/// </summary>
public string SmtpPassword
...{
get ...{ return _smtpPassword; }
set ...{ _smtpPassword = value; }
}
private string _content;
/**//// <summary>
/// 邮件内容
/// </summary>
public string Content
...{
get ...{ return _content; }
set ...{ _content = value; }
}
private string _title;
/**//// <summary>
/// 邮件标题
/// </summary>
public string Title
...{
get ...{ return _title; }
set ...{ _title = value; }
}
private string[] _cc = null;
/**//// <summary>
/// 抄送邮箱
/// </summary>
public string[] cc
...{
get ...{ return _cc; }
set ...{ _cc = value; }
}
private string[] _bcc = null;
/**//// <summary>
/// 密送邮箱
/// </summary>
public string[] bcc
...{
get ...{ return _bcc; }
set ...{ _bcc = value; }
}
/**//// <summary>
///发送邮件
/// </summary>
/// <returns>返回是否成功</returns>
public bool Send()
...{
try
...{
MailMessage objMailMessage;
objMailMessage = new MailMessage(SendEmail, _getemail, _title, _content);
if (!string.IsNullOrEmpty(_replyToEmail) && !string.IsNullOrEmpty(_replyUserName))
...{
MailAddress reply = new MailAddress(_replyToEmail, _replyUserName);
objMailMessage.ReplyToList.Add(reply);
}
objMailMessage.BodyEncoding = Encoding.GetEncoding(936);
objMailMessage.IsBodyHtml = true;
if (cc != null && cc.Length > 0)
...{
foreach (string ccAddress in cc)
...{
objMailMessage.CC.Add(new MailAddress(ccAddress));
}
}
if (bcc != null && bcc.Length > 0)
...{
foreach (string bccAddress in bcc)
...{
objMailMessage.Bcc.Add(new MailAddress(bccAddress));
}
}
SmtpClient client = new SmtpClient(this._host, this._port);
if (!String.IsNullOrEmpty(this.SmtpUsername) && !String.IsNullOrEmpty(this.SmtpPassword))
...{
client.Credentials = new NetworkCredential(this.SmtpUsername, this.SmtpPassword);
}
client.EnableSsl = false;
client.Send(objMailMessage);
objMailMessage.Dispose();
return true;
}
catch
...{
return false;
}
}
}