资源简介
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
namespace MyCommon
{
public class SendEmail
{
private MailMessage mailMessage;
private SmtpClient smtpClient;
/// <summary>
/// 处审核后类的实例
/// </summary>
/// <param name="To">收件人地址</param>
/// <param name="From">发件人地址</param>
/// <param name="Body">邮件正文</param>
/// <param name="Title">邮件的主题</param>
/// <param name="Password">发件人密码</param>
public void SetValue(string To, string From, ref string Body, ref string Title, string Password, bool EnableSsl,bool isBodyHtml)
{
mailMessage = new MailMessage();
mailMessage.To.Add(To);
mailMessage.From = new System.Net.Mail.MailAddress(From);
mailMessage.Subject = Title;
mailMessage.Body = Body;
mailMessage.IsBodyHtml = isBodyHtml;
mailMessage.BodyEncoding = System.Text.Encoding.Default;
mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential(mailMessage.From.Address, Password);//设置发件人身份的票据
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Port = 25;//Gmail使用的端口
smtpClient.Host = "smtp." mailMessage.From.Host;
smtpClient.EnableSsl = EnableSsl;//经过ssl加密
}
/// <summary>
/// 异步发送邮件
/// </summary>
/// <param name="CompletedMethod"></param>
public void SendAsync(SendCompletedEventHandler CompletedMethod)
{
smtpClient.SendCompleted = new SendCompletedEventHandler(CompletedMethod);//注册异步发送邮件完成时的事件
smtpClient.SendAsync(mailMessage, mailMessage.Body);
}
/// <summary>
/// 发送邮件
/// </summary>
public void Send()
{
smtpClient.Send(mailMessage);
}
/// <summary>
/// 添加附件
/// </summary>
public void Attachments(string Path)
{
string[] path = Path.Split(',');
Attachment data;
ContentDisposition disposition;
for (int i = 0; i < path.Length; i )
{
data = new Attachment(path[i], MediaTypeNames.Application.Octet);//实例化 附件
disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(path[i]);//获取 附件的创建日期
disposition.ModificationDate = System.IO.File.GetLastWriteTime(path[i]);//获取附件的修改日期
disposition.ReadDate = System.IO.File.GetLastAccessTime(path[i]);//获取附件的读取日期
mailMessage.Attachments.Add(data);//添加到附件中
}
}
}
}
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
namespace MyCommon
{
public class SendEmail
{
private MailMessage mailMessage;
private SmtpClient smtpClient;
/// <summary>
/// 处审核后类的实例
/// </summary>
/// <param name="To">收件人地址</param>
/// <param name="From">发件人地址</param>
/// <param name="Body">邮件正文</param>
/// <param name="Title">邮件的主题</param>
/// <param name="Password">发件人密码</param>
public void SetValue(string To, string From, ref string Body, ref string Title, string Password, bool EnableSsl,bool isBodyHtml)
{
mailMessage = new MailMessage();
mailMessage.To.Add(To);
mailMessage.From = new System.Net.Mail.MailAddress(From);
mailMessage.Subject = Title;
mailMessage.Body = Body;
mailMessage.IsBodyHtml = isBodyHtml;
mailMessage.BodyEncoding = System.Text.Encoding.Default;
mailMessage.Priority = System.Net.Mail.MailPriority.Normal;
smtpClient = new SmtpClient();
smtpClient.Credentials = new System.Net.NetworkCredential(mailMessage.From.Address, Password);//设置发件人身份的票据
smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtpClient.Port = 25;//Gmail使用的端口
smtpClient.Host = "smtp." mailMessage.From.Host;
smtpClient.EnableSsl = EnableSsl;//经过ssl加密
}
/// <summary>
/// 异步发送邮件
/// </summary>
/// <param name="CompletedMethod"></param>
public void SendAsync(SendCompletedEventHandler CompletedMethod)
{
smtpClient.SendCompleted = new SendCompletedEventHandler(CompletedMethod);//注册异步发送邮件完成时的事件
smtpClient.SendAsync(mailMessage, mailMessage.Body);
}
/// <summary>
/// 发送邮件
/// </summary>
public void Send()
{
smtpClient.Send(mailMessage);
}
/// <summary>
/// 添加附件
/// </summary>
public void Attachments(string Path)
{
string[] path = Path.Split(',');
Attachment data;
ContentDisposition disposition;
for (int i = 0; i < path.Length; i )
{
data = new Attachment(path[i], MediaTypeNames.Application.Octet);//实例化 附件
disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(path[i]);//获取 附件的创建日期
disposition.ModificationDate = System.IO.File.GetLastWriteTime(path[i]);//获取附件的修改日期
disposition.ReadDate = System.IO.File.GetLastAccessTime(path[i]);//获取附件的读取日期
mailMessage.Attachments.Add(data);//添加到附件中
}
}
}
}
代码片段和文件信息
using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
namespace MyCommon
{
public class SendEmail
{
private MailMessage mailMessage;
private SmtpClient smtpClient;
///
/// 处审核后类的实例
///
/// 收件人地址
/// 发件人地址
/// 邮件正文
/// tle“>邮件的主题
/// 发件人密码
public void SetValue(string To string From ref string Body ref string title string Password bool EnableSslbool isBodyHtml)
{
mailMessage = new MailMessage();
mailMessage.To.Add(To);
mailMessage.Fr
相关资源
- C#联通网络宽带测试 拨号
- C#百度指数抓取方法(2012年版本已失
- C# 隐藏某个磁盘分区
- C# 读取并编辑window系统的右键菜单
- C#自定义屏保(不断滚动的文字)
- C#winform打印指定区域 -控件拖动 -设置
- C#使用Hook进行改键
- 提供C#调用系统API函数弹出或收起光驱
- 通过C#自带的头文件(类)获取Windo
- C#获取电脑CPU以及内存使用率
- 利用uu云打码平台的lib实现的c#打码平
- tf-idf一种计算方法
- C# pop3 邮件接收程序
- C# 邮件群发示例 源码下载18952
- 动态抓取IPC#实现
- XXTEA算法的C#实现和JS实现,可以互相
- C# 飞行棋 游戏源码(面向对象入门)
- 基于WinPcap的C# ARP欺骗软件().rar
- C#网络应用编程 矩阵并行计算练习
- 《C#版Ftp软件源码》
-
C# 播放铃声(AxWindowsMediaPla
yer)最新 - C# 把图片显示成椭圆形状
- C# 水平交错效果显示图像
- winform 浮雕效果的图像
- c# 底片效果显示图像就像旧式相机的
- 积木效果显示图像
- C# 隐形窗体 (没有边框,没有标题栏
- browerPhotoC#网页截图(不打开网页)
- C# 模拟时钟(自绘Graphics)
- C#之WPF重绘动态正弦余弦曲线
评论
共有 条评论