protected void SendMail()
{
try
{
string CreaterName = "";
string examiner = "";
List<string> mailList = GetMailList(ref CreaterName, ref examiner);

MailEntity me = new MailEntity();
MailEntity me_1 = new MailEntity();

me.AddresserMail = ConfigurationManager.AppSettings["AddresserMail"].ToString();
me.AddresserName = ConfigurationManager.AppSettings["AddresserName"].ToString();
me.AddresserPwd = ConfigurationManager.AppSettings["AddresserPwd"].ToString();

me_1.AddresserMail = ConfigurationManager.AppSettings["AddresserMail_1"].ToString();
me_1.AddresserName = ConfigurationManager.AppSettings["AddresserName_1"].ToString();
me_1.AddresserPwd = ConfigurationManager.AppSettings["AddresserPwd_1"].ToString();

string strPostfix = ConfigurationManager.AppSettings["Postfix"].ToString();
string isSend = ConfigurationManager.AppSettings["isSend"].ToString();
StringBuilder ss = new StringBuilder();
if (isSend == "1")
{
if (mailList.Count > 0)
{
foreach (string mail in mailList)
{
int count = mail.IndexOf("@");
string postfix = mail.Substring(count + 1);

string[] pf = strPostfix.Split(new char[] { '|' });
int pCount = 0;
foreach (string p in pf)
{
if (postfix == p)
{
pCount++;
break;
}
}
if (pCount > 0)
{
me.AddresseeMail = mail.ToString();
}
else
{
me_1.AddresseeMail = mail.ToString();
}
string Body = "";

try
{
using (StreamReader sr = new StreamReader(HttpRuntime.BinDirectory + "/../tpl/tpl_Debt.htm", System.Text.Encoding.Default))
{
Body = sr.ReadToEnd();
}
}
catch (Exception ex)
{
lbMessage.Text = "*** 读取模板出错(reading template failed)!" + ex.Message;
lbMessage.ForeColor = System.Drawing.Color.Red;
return;
}

// --------------------------------------------------------------------------
me.ClientHost = ConfigurationManager.AppSettings["clientHost"].ToString();
me.MailEncoding = System.Text.Encoding.GetEncoding("GB2312");
me.MailPriority = System.Net.Mail.MailPriority.Normal;
me.IsBodyHtml = true;
me.Subject = "[" + CreaterName + "]创建的借款单";
//--------------------------------------------------------------------------
me_1.ClientHost = ConfigurationManager.AppSettings["clientHost_1"].ToString();
me_1.MailEncoding = System.Text.Encoding.GetEncoding("GB2312");
me_1.MailPriority = System.Net.Mail.MailPriority.Normal;
me_1.IsBodyHtml = true;
me_1.Subject = "[" + CreaterName + "]创建的借款单";

Body = Body.Replace("DTTPL_COMM_MODULE_NAME_ExpenseName", CreaterName);//借款人
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Type", ddlDebtType_Add.SelectedItem.Text);//借款类型
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Money", txbMoney_Add.Text);//金额
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Mender", txtMender.Text);//审核人
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Time", tbxDebtTime_Add.Text);//借款时间
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Advance", tbAdvance.Text);//代/垫款单位
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_DebtPathWay", ddlDebtPathWay.SelectedItem.Text);//借款方式
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Remark", txbMemo_Add.Text);//借款事由
// Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Mend", "");//审核意见
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Memo", "");//备注
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Replace("http://", "");
int index = url.IndexOf("/");
url = "http://" + url.Substring(0, index + 1);
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_LINK", url + "Affair/SelectWorkEvent.aspx?typeid=249");

me.Body = Body;
me_1.Body = Body;

if (me.AddresseeMail == null && me.CopyToAddresseeMail == null && me_1.AddresseeMail == null && me_1.CopyToAddresseeMail == null)
{
lbMessage.Text = "*** 借款单保存成功! 但责任人/关注人因在数据库没有存邮箱地址,邮件未曾发送!";
lbMessage.ForeColor = System.Drawing.Color.Red;
return;
}
if (me.AddresseeMail != null || me.CopyToAddresseeMail != null)
{
bool temp = false;
for (int y = 0; y < 3; y++)
{
try
{
if (MailServer.SendMail(me))
{
temp = true;
break;
}
}
catch (Exception ex)
{
continue;
}

}
if (!temp)
{
if (me.AddresseeMail != null)
{
ss.Append(me.AddresseeMail.Trim());
}
if (me.CopyToAddresseeMail != null && me.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me.CopyToAddresseeMail.Trim());
}
}
me.AddresseeMail = null;
}
if (me_1.AddresseeMail != null || me_1.CopyToAddresseeMail != null)
{
bool temp = false;
for (int y = 0; y < 3; y++)
{
try
{
if (MailServer.SendMail(me_1))
{
temp = true;
break;
}
}
catch (Exception ex)
{
continue;
}
}
if (!temp)
{
if (ss.ToString().Trim() != "")
{
ss.Append(",");
if (me_1.AddresseeMail != null)
ss.Append(me_1.AddresseeMail.Trim());
if (me_1.CopyToAddresseeMail != null && me_1.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me_1.CopyToAddresseeMail.Trim());
}
}
else
{
if (me_1.AddresseeMail != null)
ss.Append(me_1.AddresseeMail.Trim());
if (me_1.CopyToAddresseeMail != null && me_1.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me_1.CopyToAddresseeMail.Trim());
}
}
}
me_1.AddresseeMail = null;
}
}
}
}
}
catch (Exception ex)
{
lbMessage.Text = "*** 发送失败(the email is not sent)!" + ex.ToString();
lbMessage.ForeColor = System.Drawing.Color.Red;
}
}

asp.net发邮件功能的更多相关文章

  1. Nagios 配置自动发邮件功能

    安装sendmailyum install -y sendmail* mailx 修改防火墙设置,添加25端口到防火墙vi /etc/sysconfig/iptables 重启 iptables.se ...

  2. Java实现发邮件功能---网易邮箱

    目录 Java实现发邮件功能 前言 开发环境 代码 效果 结束语 Java实现发邮件功能 前言 电子邮件的应用场景非常广泛,例如新用户加入,即时发送优惠清单.通过邮件找回密码.监听后台程序,出现异常自 ...

  3. Selenium 2自动化测试实战38(整合自动发邮件功能)

    整合自动发邮件功能 解决了前面的问题后,现在就可以将自动发邮件功能集成到自动化测试项目中了.下面重新编辑runtest.py文件 #runtest.py #coding:utf-8 from HTML ...

  4. Selenium 2自动化测试实战37(自动发邮件功能)

    自动发邮件功能 例如,如果想在自动化脚本运行完成之后,邮箱就可以收到最新的测试报告结果.SMTP(Simple Mail Transfer Protocol)是简单邮件传输协议,它是一组用于由源地址到 ...

  5. 【知识积累】JavaMail实现发邮件功能

    一.前言 今天闲来没事,想着通过程序来给别人发邮件.于是,上网搜了一下,相应的资料也很多,刚开始完成了邮件的简单发送,后来想如何能发送附件,继续寻找 答案,但是遇到了一个问题是当我使用txt类型作为附 ...

  6. iOS打电话、发短信、发邮件功能开发

    本文转载至 http://www.lvtao.net/ios/506.html 今天把APP里常用小功能 例如发短信.发邮件.打电话.全部拿出来简单说说它们的实现思路. 1.发短信实现打电话的功能,主 ...

  7. Thinkphp5的使用phpmailer实现发邮件功能(163邮箱)

    Thinkphp5本身并没有实现发邮件的功能,至少据我所知. 本文利用网易邮箱作为发邮件的邮箱.作为发送邮件的前提是需要开启SMTP服务,打开网易邮件,点击设置按钮,如下图所示 勾选smtp服务 保存 ...

  8. 使用Django实现发邮件功能

    django实现发送邮件功能   django实现邮件发送功能 1)首先注册一个邮箱,这里以163邮箱为例 2)注册之后登录,进行如下修改 找到设置,设置一个授权码,授权码的目的仅仅是让你有权限发邮件 ...

  9. c# 发邮件功能

    using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using Sy ...

随机推荐

  1. 判断checkbox是否选中

    一种是通过jquery A. $("[name='selectUserId']:checked").each(function () { // $(this).attr(" ...

  2. 笔记汇总.md

    ```javascript 1.js对象,value的值取不到,试着将引入的js文件放到body的后面 $("input[type='time']").change( functi ...

  3. Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  4. 每天一点Android干货-Activity的生命周期

    Activity Activity是这样一个程序组件,它为用户提供一个用于任务交互的画面. 一个应用程序通常由多个activity组成,它们彼此保持弱的绑定状态.典型的,当一个activity在一个应 ...

  5. PHP之图片上传类(加了缩略图)

    有缩略图功能 但是 感觉不全面,而且有点问题,继续学习,将来以后修改下 <form action="<?php $_SERVER['PHP_SELF']; ?>" ...

  6. Web Api 简介

    ASP.NET Web API 简介  ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP. ...

  7. Bootstrap Affix(附加导航(Affix)插件的用法)

    原文网址:http://www.runoob.com/bootstrap/bootstrap-affix-plugin.html Bootstrap 附加导航(Affix)插件 附加导航(Affix) ...

  8. mysql 自动备份和nginx自动安装脚本

    一.自动备份Mysql脚本: 如下脚本为mysql自动备份脚本,仅供参考,可以根据实际情况修改. #!/bin/sh #auto backup mysql #wugk #Define PATH定义变量 ...

  9. modprobe和lsmod命令配合使用

    modprobe命令用于智能地向内核中加载模块或者从内核中移除模块. modprobe可载入指定的个别模块,或是载入一组相依的模块.modprobe会根据depmod所产生的相依关系,决定要载入哪些模 ...

  10. Ubuntu .deb包安装方法

    使用apt-get方法安装的软件,所有下载的deb包都缓存到了/var/cache/apt/archives目录下了,所以可以把常用的deb包备份出来,甚至做成ISO工具包.刻盘,以后安装Ubuntu ...