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. ...
随机推荐
- Metinfo4.0 /member/save.php 任意用户密码修改
- react 中 EventEmitter 事件总线机制
此机制可用于 react 中兄弟组件中的通信 npm install events -S 事件总线: // eventBus.js import {EventEmitter} from 'events ...
- 洛谷 P2015 二叉苹果树 题解
题面 裸的树上背包: 设f[u][i]表示在以u为子树的树种选择i条边的最大值,则:f[u][i]=max(f[u][i],f[u][i-j-1]+f[v][k]+u到v的边权); #include ...
- selenium获取微博用户粉丝数
selenum的安装 selenium文档 获取微博用户粉丝数 from selenium import webdriver from time import sleep wd = webdriver ...
- redis 小结 一
1.redis 是什么? 它是一个key-value存储系统,也被称为数据结构服务器,它的值是字符串(String),哈希(Hash),列表(list),集合(sets)和有序集合(sorted se ...
- Python 入门之 内置模块 -- sys模块
Python 入门之 内置模块 -- sys模块 1.sys模块 sys模块是与python解释器交互的一个接口 print(sys.path) #模块查找的顺序 print(sys.argv) # ...
- 手把手教你vue配置请求本地json数据
本篇文章主要介绍了vue配置请求本地json数据的方法,分享给大家,具体如下:在build文件夹下找到webpack.dev.conf.js文件,在const portfinder = require ...
- 记一次神奇的codeforces
今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...
- 解决Response.AddHeader中文乱码问题
string filename = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes("培训班自然情况表")); Response.AddH ...
- luogu P4076 [SDOI2016]墙上的句子
luogu loj 题意看了我半天(逃 (应该是我语文太差了) 题意是要确定每一行和每一列的看单词的顺序,使得同时正着出现和反着出现在里面的单词数量最少,每行和每列的性质是这一行所有单词反过来的单词要 ...