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. ...
随机推荐
- C#程序员经常用到的10个实用代码片段 - 操作系统
原文地址 如果你是一个C#程序员,那么本文介绍的10个C#常用代码片段一定会给你带来帮助,从底层的资源操作,到上层的UI应用,这些代码也许能给你的开发节省不少时间.以下是原文: 1 读取操作系统和C ...
- 抖音很火的存钱计划,让python告诉你总共可以存到多少钱!
抖音上有个很火的存钱计划,说是第一天存1块钱,第二天存2块钱,第三天存3块钱.....依此类推存365天,总共可以存到多少钱,我们现在用python告诉你怎么做: #定个初始存入金额 money = ...
- Codeforces - 1203D2 - Remove the Substring (hard version) - 双指针
https://codeforces.com/contest/1203/problem/D2 上次学了双指针求两个字符串之间的是否t是s的子序列.但其实这个双指针可以求出的是s的前i个位置中匹配t的最 ...
- 什么是RESTful API、WSGI、pecan
RESTful API REST的全称是Representational State Transfer(表征状态转移), 是Roy Fielding在他的博士论文Architectural Style ...
- git大全转
git原理:https://git-scm.com/book/zh/v2 http://blog.xiayf.cn/2013/09/28/learning-git-internals-by-examp ...
- Centos7安装升级Ruby和集群搭建参考
安装升级Ruby参考:https://blog.csdn.net/qq_26440803/article/details/82717244 集群搭建参考:https://www.cnblogs.com ...
- Delphi 帮助的使用
- Linux学习之CentOS(二十六)--Linux磁盘管理:LVM逻辑卷的创建及使用
在上一篇随笔里面 Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理,详细的讲解了Linux的动态磁盘管理LVM逻辑卷的基本概念以及LVM的工作原理, ...
- 页面中获取 iframe 中的值
3.页面中获取 iframe 中的值 var obj=document.getElementsByClassName(".ke-edit-iframe").contentWindo ...
- 对mysql进行快照复制
Myself> flush tables with read lock; 之后开始创建快照 [root@server0 mysql]# lvcreate -L 100M -s -n dbback ...