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. unity3d随机地牢生成代码

    现在也是处于失业状态,碰巧看到个面试题是要用unity生成个随机地牢,就把做题过程中的思路和代码记录一下吧. 做完了以后我又想了一下,发现其实根本不需要这么麻烦,果然demo里的代码对我的思路影响还是 ...

  2. http协议梳理(个人学习用)

    HTTP默认的端口号为80,HTTPS的端口号为443. 在Internet中所有的传输都是通过TCP/IP进行的.HTTP协议作为TCP/IP模型中应用层的协议.HTTP协议通常承载于TCP协议之上 ...

  3. Metro-Ural119递推

    Time limit: 0.5 second Memory limit: 64 MB Many of SKB Kontur programmers like to get to work by Met ...

  4. error: could not read CFBundleIdentifier from Info.plist (null)解决方法之一

    出现这种错误的原因可能很多,以下是我遇到的一种情况: 项目移植到新的环境 编译报错:  error: could not read CFBundleIdentifier from Info.plist ...

  5. Apache设置页面认证(原创贴-转载请注明出处)

    ================写在前面的话============== 1.本试验使用的apache版本是2.4.24 场景描述:网站后台管理页面比较重要,不应该任何人都让访问,所以对后台页面做认证 ...

  6. C#中浮点数依IEEE-754标准转二进制串 (MODBUS 浮点数转换)

    因工作需要,把再串口通信中浮点数与字节流的数据转换函数放在这,转发的,谢谢原作者. 今天花了一天的时间搜罗资料,为了解决一个串口编程的进制转化问题.因为串口传送的浮点数据格式与IEEE-754标准(3 ...

  7. JS汉语转拼音脚本

    测试代码: var anhui = "安徽"; //获得全拼 pinyin.getFullChars(anhui); //获得首拼 pinyin.getCamelChars(anh ...

  8. HDFS shell

    bin/hdfs -help bin/hdfs dfs -mkdir -p /yfq/test/ bin/hdfs dfs -put /etc/profile /yfq/test/profile 上传 ...

  9. Download Oracle Forms 6i

    To download Oracle Forms Developer 6i from Oracle click this link http://download.oracle.com/otn/nt/ ...

  10. PHP 编译安装

    1, 获取源码wget -O php.tar.gz http://am1.php.net/get/php-5.6.27.tar.gz/from/this/mirrortar zxvf php.tar. ...