邮件发送类
来源:互联网 发布:vivoy67怎么设置网络 编辑:程序博客网 时间:2024/06/03 09:26
邮件发送类,使用简单方便
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace LZ2007.Function
{
/// <summary>
/// 邮件发送类
/// <CreateDate>2007/07/02</CreateDate>
/// <ModifyDate>2007/07/02</ModifyDate>
/// <Author>张怡冰</Author>
/// </summary>
public class Mail
{
public Mail(string host, int port, string smtpUsername, string smtpPassword)
{
_host = host;
_port = port;
_smtpUsername = smtpUsername;
_smtpPassword = smtpPassword;
}
public Mail() { }
private string _host;
public string Host
{
get { return _host; }
set { _host = value; }
}
private int _port;
public int Port
{
get { return _port; }
set { _port = value; }
}
private string _smtpUsername;
public string SmtpUsername
{
get { return _smtpUsername; }
set { _smtpUsername = value; }
}
private string _smtpPassword;
public string SmtpPassword
{
get { return _smtpPassword; }
set { _smtpPassword = value; }
}
public void SendMail(string from, string to, string subject, string body, bool ssl, string[] cc, string[] bcc)
{
// Create mail message
MailMessage message = new MailMessage(from, to, subject, body);
message.BodyEncoding = Encoding.GetEncoding(936);
message.IsBodyHtml = true;
if (cc != null && cc.Length > 0)
{
foreach (string ccAddress in cc)
{
message.CC.Add(new MailAddress(ccAddress));
}
}
if (bcc != null && bcc.Length > 0)
{
foreach (string bccAddress in bcc)
{
message.Bcc.Add(new MailAddress(bccAddress));
}
}
// Send email
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);
}
if (ssl)
{
client.EnableSsl = true;
}
client.Send(message);
}
}
}
来源:http://www.cnblogs.com/eicesoft/articles/839157.html
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace LZ2007.Function
{
/// <summary>
/// 邮件发送类
/// <CreateDate>2007/07/02</CreateDate>
/// <ModifyDate>2007/07/02</ModifyDate>
/// <Author>张怡冰</Author>
/// </summary>
public class Mail
{
public Mail(string host, int port, string smtpUsername, string smtpPassword)
{
_host = host;
_port = port;
_smtpUsername = smtpUsername;
_smtpPassword = smtpPassword;
}
public Mail() { }
private string _host;
public string Host
{
get { return _host; }
set { _host = value; }
}
private int _port;
public int Port
{
get { return _port; }
set { _port = value; }
}
private string _smtpUsername;
public string SmtpUsername
{
get { return _smtpUsername; }
set { _smtpUsername = value; }
}
private string _smtpPassword;
public string SmtpPassword
{
get { return _smtpPassword; }
set { _smtpPassword = value; }
}
public void SendMail(string from, string to, string subject, string body, bool ssl, string[] cc, string[] bcc)
{
// Create mail message
MailMessage message = new MailMessage(from, to, subject, body);
message.BodyEncoding = Encoding.GetEncoding(936);
message.IsBodyHtml = true;
if (cc != null && cc.Length > 0)
{
foreach (string ccAddress in cc)
{
message.CC.Add(new MailAddress(ccAddress));
}
}
if (bcc != null && bcc.Length > 0)
{
foreach (string bccAddress in bcc)
{
message.Bcc.Add(new MailAddress(bccAddress));
}
}
// Send email
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);
}
if (ssl)
{
client.EnableSsl = true;
}
client.Send(message);
}
}
}
来源:http://www.cnblogs.com/eicesoft/articles/839157.html
- c#邮件发送 邮件类
- 邮件发送类
- 邮件发送类
- 发送邮件的类
- C#邮件发送类
- smtp 发送邮件类
- 邮件发送类
- c# 邮件发送类
- c#发送邮件类
- php发送邮件类
- 邮件发送类
- 邮件发送类
- php发送邮件类
- 发送邮件类
- PHP邮件发送类
- 邮件发送工具类
- PHP邮件发送类
- java发送邮件类
- DOM的简单介绍
- Linux信号通信小例子
- java关于23种设计模式的有趣见解
- 好文推荐(对JScript初,中级者有用):面向对象的Jscript[转贴]
- Class.forName的含义
- 邮件发送类
- 新生高考成绩按专业分布统计
- 统计jsp 中如何获取sql2000的字段
- Linux设备驱动程序与外界的接口
- 关于ArcSDE Oracle9i 不能正常建立服务的几个解决方案
- HTML标签综合
- 上海海运/空运出口流程
- 可输入的下拉框的复合控件
- 禁用IE退格键及其他键脚本