Send Email
private string SendEmail(string mailTo, string body, ref int sendresult)
{
string errorEmailAddress = "";
SmtpClient smtp = new SmtpClient(_SmtpServer);
try
{ MailMessage message = new MailMessage();
message.Priority = MailPriority.High;
message.From = new MailAddress(_From);
//message.To.Add(mailTo);
message.Subject = _Subject;
message.Body = body;
message.IsBodyHtml = true;
message.Bcc.Add(new MailAddress(_Bcc, "", Encoding.Default));
SetToMailAddress(mailTo, message, ref errorEmailAddress);
if (message.To.Count > )
{
smtp.Send(message);
sendresult = ;
}
smtp.Dispose();
return string.IsNullOrEmpty(errorEmailAddress) ? string.Empty : ("Error email address:"+errorEmailAddress);
}
catch (Exception e)
{
smtp.Dispose();
return e.InnerException.Message + (string.IsNullOrEmpty(errorEmailAddress) ? "" : (" Error email address: " + errorEmailAddress));
}
}
private static void SetToMailAddress(string toMailAddress, MailMessage message, ref string errorEmailAddress)
{
string[] addes = toMailAddress.Split(';').ToArray();
foreach (string s in addes)
{
if (Regex.IsMatch(s, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"))
{
message.To.Add(new MailAddress(s.Trim(), "", Encoding.Default));
}
else
{ errorEmailAddress += s + ";"; }
}
}
Send Email的更多相关文章
- Try to write a script to send e-mail but failed
#-*-coding: utf-8 -*- '''使用Python去发送邮件但是不成功,运行后,等待一段时间, 返回[Errno 10060] A connection attempt failed ...
- python auto send email
/*************************************************************************** * python auto send emai ...
- Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email
Check SMTP Server Availability for ORA-29278 or ORA-29279 errors using UTL_SMTP to Send Email. (文档 I ...
- Send Email in Robot Framework Python Using Gmail
转载自:http://seleniummaster.com/sitecontent/index.php/selenium-robot-framework-menu/selenium-robot-fra ...
- 5 Ways to Send Email From Linux Command Line
https://tecadmin.net/ways-to-send-email-from-linux-command-line/ We all know the importance of email ...
- [476] Database Mail is not enabled for agent notifications. Cannot send e-mail to
配置完DB Mail后JOB的的通知邮件不能发送,日志报错476] Database Mail is not enabled for agent notifications. Cannot send ...
- Send email alert from Performance Monitor using PowerShell script (检测windows服务器的cpu 硬盘 服务等性能,发email的方法) -摘自网络
I have created an alert in Performance Monitor (Windows Server 2008 R2) that should be triggered whe ...
- .Net Core Send Email
1.安装Nuget包MailKit,引用命名空间. using MailKit.Net.Smtp; using MimeKit; 注意:引用MailKit对应最新版本 2.定义收发地址和标题 Mime ...
- How to send Email using C#
try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail. ...
随机推荐
- mybatis返回List<Map>
mapperl.xml中: <select id="getAmount" parameterType="int" resultType="jav ...
- Zookeeper群起脚本启动失败及查看状态出现:Error contacting service. It is probably not running
1.问题: 群起脚本启动后查看jps没有出现:QuorumPeerMain Zookeeper正常启动但是群起脚本查状态出现:Error contacting service. It is proba ...
- CF 11D A Simple Task 题解
题面 这道题的数据范围一看就是dfs或状压啦~ 本文以状压的方式来讲解 f[i][j]表示目前的节点是i,已经经历过的节点的状态为j的简单环的个数: 具体的转移方程和细节请看代码: PS:(i& ...
- 利用Kruskal算法求最小生成树解决聪明的猴子问题 -- 数据结构
题目:聪明的猴子 链接:https://ac.nowcoder.com/acm/problem/19964 在一个热带雨林中生存着一群猴子,它们以树上的果子为生.昨天下了一场大雨,现在雨过天晴,但整个 ...
- hugo搭建个人博客
本地先安装git 1. 下载hugo,并配置好环境变量 我这里win7 64位,选择该版本下载 将解压后的hugo.exe,配置到环境变量中,如下图所示表明配置成功 hugo version 2. 生 ...
- 从window 的cmd窗口中下载linux 服务器上文件
下载linux 服务器上的文件 down.php 格式为 pscp linux服务器上用户名@linux 服务器ip 文件在windows系统上的绝对路径 如果是下载服务器上的某个目录,只要在ps ...
- javaweb: request.getParameter()、request.setAttribute()与request.getAttribute()的作用 (转)
出处:https://blog.csdn.net/qq_41937388/article/details/87972914 1.request.getParameter()方法是获取通过类似post, ...
- 2019icpc徐州网络赛
A Who is better? 题意 excrt+斐波那契博弈 分析 Java的BigInteger对象默认为null,不能直接比较. 代码 import java.math.BigInteger; ...
- python 父子节点生成字典
lines = [(1, 1, '父1节点'), (2, 1, '1-2'), (3, 1, '1-3'), (4, 3, '1-3-4'), (5, 3, '1-3-5'), (6, 3, '1-3 ...
- 关于android studio从2.3升级到3.0以上可能会遇到的问题
请参考链接: http://blog.csdn.net/hylczp/article/details/60137958 gradle-3.3-all网盘下载地址: 链接:http://pan.baid ...