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. ...
随机推荐
- Kaggle试水之泰坦尼克灾难
比赛地址:https://www.kaggle.com/c/titanic 再次想吐槽CSDN,编辑界面经常卡死,各种按钮不能点,注释的颜色不能改,很难看清.写了很多卡死要崩溃. 我也是第一次参加这个 ...
- vue项目与node项目分离
为了前后端分离,我们在前端和api层中间,架构了一层node层,用来做服务端渲染,来加快用户的首屏可用和对搜索引擎的友好.项目一开始放置在同一个git仓库里面,分别放在client目录和server目 ...
- 【VS开发】Windows上的音频采集技术
前一段时间接到一个任务,需要采集到声卡的输出信号,以便与麦克风的输入信号进行混音. 之前一直没有研究过音频的相关技术,这次就顺便抽出一点时间去了解了一下Windows上采集音频的相关技术. 对于音频处 ...
- 未能加载文件或程序集“microsoft.Build.Engine, Version=3.5.0.0,...”或它的摸一个依赖项。
今天想打开IIS服务,然后点错了,不小心关掉了.net组件,结果vs就一直打不开项目,最后在网上查到了原因,打开 控制面板->程序和功能->打开或关闭功能 在里面勾选Microsoft . ...
- xpath 的用法
爬虫利器xpath xpath术语 节点(node)
- 微信小程序--catchtap&bindtap
转自:https://www.cnblogs.com/heron-yu/p/7244481.html 转自:http://blog.csdn.net/xiaochun365/article/detai ...
- airflow部署
官网: http://airflow.apache.org/installation.html 原理: https://www.cnblogs.com/cord/p/9450910.html 安装: ...
- nodejs以对象做对象的key导致value一直被覆盖
问题描述 在开发中,实现技能状态的事件监听功能时,将状态对象作为key,存入事件管理器的监听列表,如下图: 实现后,运行程序,并没有报错,但是当某个事件发生时,只有一个状态被触发监听,而大多数状态 ...
- Office批量授权(VL)版本和激活方法
Office 2010 Office 2010中文专业增强版 32位 文件名: SW_DVD5_Office_Professional_Plus_2010w_SP1_W32_ChnSimp_CORE_ ...
- windows 通过cmd命令行管理防火墙
(1)恢复初始防火墙设置 netsh advfirewall reset(2)关闭防火墙 netsh advfirewall set allprofiles state off(3)启用桌面防火墙 n ...