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. ...
随机推荐
- ROS系统的安装以及卸载
ROS系统的安装 ROS系统的安装方式有两种,通过软件源和源码编译安装.软件源安装只需要通过简单的命令,因此,我们使用软件源来安装ROS 配置系统软件源 打开Ubuntu软件中心的软件源配置界面,勾选 ...
- Leetcode基础篇30天30题系列之数组:模拟计算法
作者:丁宋涛 数组:加一 题干: 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整 ...
- 1.2.2 OSI参考模型 下
[今天打酱油了,纯抄书.OSI太重要,不敢随便乱写.] 一.开放系统互联参考模型 答:20世纪80年代初,ISO提出来著名的开放系统互联参考模型[Open Systems Interconnectio ...
- Java Web - 笔记(1)
1.web.xml Attribute "xmlns:xsi" must be declared for element type "web-app"相关报错解 ...
- python中魔法方法__str__与__repr__的区别
提出问题 当我们自定义一个类时,打印这个类对象或者在交互模式下直接输入这个类对象按回车,默认显示出来的信息好像用处不大.如下所示 In [1]: class People: ...: def __in ...
- phpstudy配置多站点
1.打开vhosts.conf文件 目录 Apache/conf/vhosts.conf #开启apache的vhost模块 (此模块默认是关闭的,去掉前面的#号) LoadModule vh ...
- java 字符串锁
package com.example.demo.controller; public class StringLock { public void method(String p) { // new ...
- 作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书
原文:作业调度框架Quartz.NET-现学现用-02-任务监听 - 简书 前言 任务调度系统并不是完美的,它会出现任务执行失败的情况.如果你需要处理任务失败后的逻辑,希望这篇笔记可以为你提供些帮助. ...
- 用python 获取照片的Exif 信息(获取拍摄设备,时间,地点等信息)
第一步:先安装 pip install exifread 第二部:上代码 import exifread import requests class PhotoExifInfo(): def __in ...
- vim最常用命令
vi/vim常用命令汇总 vi/vim概述 vi/vim是Linux和Unix下的一款非常强大的编辑器,vim是vi的增强 版,命令更加多种和复杂,但是最常用的也就是那几个. vi有三种模式 命令行模 ...