邮件发送在网站应用程序中经常会用到,包括您现在看到的博客,在添加评论后,系统会自动发送邮件通知到我邮箱的,把系统发送邮件的功能整理了下,做了一个客户端Demo,希望对有需要的童鞋有所帮助:

核心代码:
003 |
using System.Net.Mail; |
011 |
public class EmailService |
016 |
///
<param name="mailTo">收件人 |
017 |
///
<param name="subject">主题 |
018 |
///
<param name="body">内容 |
019 |
///
<returns></returns> |
020 |
public static bool Send(string mailTo, string subject, string body) |
022 |
return Send(new[]
{mailTo}, null,
subject, body, true, null); |
028 |
///
<param name="mailTo">收件人 |
029 |
///
<param name="subject">主题 |
030 |
///
<param name="body">内容 |
031 |
///
<returns></returns> |
032 |
public static bool Send(string[]
mailTo, string subject, string body) |
034 |
return Send(mailTo, null,
subject, body, true, null); |
040 |
///
<param name="mailTo">收件人 |
041 |
///
<param name="subject">主题 |
042 |
///
<param name="body">内容 |
043 |
///
<param name="attachmentsPath">附件 |
044 |
///
<returns></returns> |
045 |
public static bool Send(string[]
mailTo, string subject, string body, string[]
attachmentsPath) |
047 |
return Send(mailTo, null,
subject, body, true,
attachmentsPath); |
054 |
///
<param name="mailTo">收件人 |
055 |
///
<param name="mailCcArray">抄送 |
056 |
///
<param name="subject">主题 |
057 |
///
<param name="body">内容 |
058 |
///
<param name="isBodyHtml">是否Html |
059 |
///
<param name="attachmentsPath">附件 |
060 |
///
<returns></returns> |
061 |
public static bool Send(string[]
mailTo, string[]
mailCcArray, string subject,string body, bool isBodyHtml, |
062 |
string[]
attachmentsPath) |
066 |
var
config = ConfigHelper.GetConfig<emailconfig>(); |
067 |
if (string.IsNullOrEmpty(config.Host)
||string.IsNullOrEmpty(config.UserName)
|| |
068 |
string.IsNullOrEmpty(config.Port)
||string.IsNullOrEmpty(config.Password)) |
073 |
var
@from = new MailAddress(config.MailFrom); //使用指定的邮件地址初始化MailAddress实例 |
074 |
var
message = new MailMessage(); //初始化MailMessage实例 |
078 |
foreach (string t in mailTo) |
085 |
if (mailCcArray
!= null) |
087 |
foreach (string t in mailCcArray) |
093 |
message.From
= @from; |
096 |
message.Subject
= subject; |
099 |
message.SubjectEncoding
= Encoding.UTF8; |
105 |
message.BodyEncoding
= Encoding.Default; |
106 |
message.Priority
= MailPriority.High; |
107 |
message.IsBodyHtml
= isBodyHtml; |
110 |
if (attachmentsPath
!= null &&
attachmentsPath.Length > 0) |
112 |
foreach (string path in attachmentsPath) |
114 |
var
attachFile = new Attachment(path); |
115 |
message.Attachments.Add(attachFile); |
120 |
var
smtp = new SmtpClient |
122 |
Credentials
= new NetworkCredential(config.UserName,
config.Password), |
124 |
Port
= Convert.ToInt32(config.Port) |
132 |
catch (SmtpException
ex) |
138 |
catch (SmtpException
ex) |
源代码下载
版权声明:本文为博主原创文章,未经博主允许不得转载。
- C# SMTP邮件发送 分类: C# 2014-07-13 19:10 333人阅读 评论(1) 收藏
邮件发送在网站应用程序中经常会用到,包括您现在看到的博客,在添加评论后,系统会自动发送邮件通知到我邮箱的,把系统发送邮件的功能整理了下,做了一个客户端Demo,希望对有需要的童鞋有所帮助: 核心代码: ...
- 浅谈IOS8之size class 分类: ios技术 2015-02-05 19:06 62人阅读 评论(0) 收藏
文章目录 1. 简介 2. 实验 3. 实战 3.1. 修改 Constraints 3.2. 安装和卸载 Constraints 3.3. 安装和卸载 View 3.4. 其他 4. 后话 以前和安 ...
- Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏
Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...
- Power Strings 分类: POJ 串 2015-07-31 19:05 8人阅读 评论(0) 收藏
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 二分图匹配 分类: ACM TYPE 2014-10-01 19:57 94人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> using namespace std; bool map[505][505]; int n, k; bo ...
- Brush Mode --- Nyoj 737 分类: Brush Mode 2014-03-25 08:10 202人阅读 评论(0) 收藏
石子合并(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆 ...
- Hibernate检索方式 分类: SSH框架 2015-07-10 22:10 4人阅读 评论(0) 收藏
我们在项目应用中对数据进行最多的操作就是查询,数据的查询在所有ORM框架中也占有极其重要的地位.那么,如何利用Hibernate查询数据呢?Hibernate为我们提供了多种数据查询的方式,又称为Hi ...
- Can you find it? 分类: 二分查找 2015-06-10 19:55 5人阅读 评论(0) 收藏
Description Give you three sequences of numbers A, B, C, then we give you a number X. Now you need t ...
随机推荐
- 网页嵌入swf代码
<object class id="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://dow ...
- VB 编程
error播放出错提示音 errorPromptVoice() 返回一个字符串,其中包含从某个字符串右端开始的指定数量的字符 Microsoft.VisualBasic.Right(strBt45Te ...
- 火狐浏览器,关闭ssl v3防护
某些网站,没有及时更新,导致火狐觉得有安全隐患,不给访问. --------------- Hello bcasey9090, go to about:config, copy the next bo ...
- bootstrap框架----像素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- VS 2012: Post build 中使用 Signtool.exe,对于特殊password中字符的处理方法
众所周知,在VS(Visual Studio)里面可以利用post build 进行一些类似于CMD或者批处理的操作. 最近的项目中用到了MicroSoft的SignTool工具,目的是要把一个数字签 ...
- Ubuntu下安装eclipse
一.eclipse安装环境JDK的安装 1.下载JDK 从官网下载jdk8 jdk-8u5-linux-x64.tar.gz 2.解压$ tar -zxvf jdk-8u5-linux-x64.tar ...
- lol 正在刷leetcode
letcode easy 刷了90%了 我要写个随笔庆祝下 挑着做的太不要脸了,接下来要做剩下的了 :) 剩下的决定直接参考答案了 :) 有些答案看着也好迷糊.水平太差了.(英文水平差,看不懂题目.. ...
- android上的图片占用内存问题
近日正在把ios程序移植到android上,以前没做过android的程序,于是,想当然地把ios的图片资源放到了android工程的drawable文件夹下,这些图片都是png. 程序界面也很正常. ...
- linux (RHEL) 添加和删除用户
linux添加新用户使用 useradd -----create a new user or update default new user information 删除用户使用userdel -- ...
- 针对SYN洪水攻击的防御措施
可以运用sysctl命令进行配置,由于本命令参数较多,这里只简单记录几个比较常用的参数: 1.tcp_max_syn_backlog 这个参数指定了后备队列可维持的TCP半开连接的数目,如果该值设定很 ...