SSIS Send Mail
在SSIS中Send Mail的方法主要有三种,使用Send Mail Task,使用Script Task和使用存储过程msdb.dbo.sp_send_dbmail。
一,使用Send Mail Task
Send Mail Task 是SSIS提供的Task,使用非常简单,但有限制:
- 只能发送普通的文本格式的邮件,不支持 HTML 格式的邮件。
- 链接到SMTP Server有两种验证方式,在域中使用 Windows 方式验证,或使用匿名验证。
- SMTP Server 使用默认的端口号25
Send Mail Task的限制是跟SMTP connection manager的配置有关

SMTP Sever:输入SMTP Server的URL
Authentication:如果选择Use Winodows Authentication,那么用户必须在域中,使用Windows账户验证;如果不选择Use Winodows Authentication,那么验证方式就是使用匿名访问SMTP Server,如果SMTP Server支持匿名访问,那么验证失败。
Enable Secure Sockerts Layer(SSL):是否对数据加密,SSL用以保障在Internet上数据传输之安全,利用数据加密(Encryption)技术,可确保数据在网络上之传输过程中不会被截取及窃听
Timeout:超时时间
Package中使用Send Mail Task发送mail,这个mail带excel的附件,当成功发送一定数量的mail之后,发现一个问题,错误信息是
System.IO.IOException:Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.
经过测试,错误原因可能是SMTP Server为链接预留缓存空间(8M),当附件的数据量到达8M阈值时,SMTP返回错误信息,将链接强制关闭。
Send Mail Task在循环使用SMTP Server的链接时,打开链接后,不会自动关闭。
我的疑问:为什么SMTP Server的链接不会自动关闭?
二,使用存储过程msdb.dbo.sp_send_dbmail
在Execute SQL Task中使用存储过程msdb.dbo.sp_send_dbmail 发送数据库邮件
三,使用Script Task,编写脚本发送mail
编写C#代码发送mail,主要是使用System.Net.Mail 类库来实现,需要添加命名空间
using System.Net.Mail;
使用Script Task,能够使用HTML格式,也能使用密码进行验证,因此适用面光,能够编写格式比较丰富的邮件。
示例代码
public void Main()
{
//Define Smtp client
int smtpPort = ;
String smtpServer = "smtp server url";
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = smtpServer;
smtpClient.Port = smtpPort; //Use Password Authentication
string loginUser = "";
string loginPwd = ""; System.Net.NetworkCredential myCredentials =
new System.Net.NetworkCredential(loginUser, loginPwd);
smtpClient.Credentials = myCredentials; //Use anonymous Authentication
//smtpClient.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; //define mail message
MailMessage message = new MailMessage(); //Define mail address
MailAddress fromAddress = new MailAddress("Sender Address", "Sender Name");
MailAddress toAddress = new MailAddress("Recipient Address", "Recipient Name"); message.From = fromAddress;
message.To.Add(toAddress);
//message.To.Add("Recipient Address"); message.Subject = "mail subject"; //Define Mail Body
message.Body = "text Mail Body";
message.IsBodyHtml = false; //message.Body = "html mail body";
//message.IsBodyHtml = true; // add attachment
string strAttachedFilePath="";
Attachment attachment = new Attachment(strAttachedFilePath);
message.Attachments.Add(attachment); //Define Mail Priority
int iPriority = ;
switch (iPriority)
{
case :
message.Priority = MailPriority.High;
break;
case :
message.Priority = MailPriority.Low;
break;
default:
message.Priority = MailPriority.Normal;
break;
} smtpClient.Send(message); //Dispose attachment
attachment.Dispose(); //Dispose Message
message.Dispose(); //Dispose Stmp client
smtpClient.Dispose(); // Close Script Task with success
Dts.TaskResult = (int)ScriptResults.Success;
}
注意:如果不将Attachment Dispose,循环使用附件时,SSIS会报附件正在被其他process使用的异常。
参照资料:
http://www.cnblogs.com/biwork/p/3999123.html
http://www.codeproject.com/Articles/85172/Send-Email-from-SSIS-with-option-to-indicate-Email
SSIS Send Mail的更多相关文章
- How to attach multiple files in the Send Mail Task in SSIS
Let’s say you need to create a SSIS package that creates 2 files and emails the files to someone. Yo ...
- mailsend - Send mail via SMTP protocol from command line
Introduction mailsend is a simple command line program to send mail via SMTP protocol. I used to sen ...
- 发送邮件的三种方式:Send Mail Message
发送邮件的三种方式: 1.VBS 执行vbs脚本文件的程序为: system32文件下的 NameSpace = "http://schemas.microsoft.com/cdo/conf ...
- Send Mail using C# code
using System.Net.Mail; public class MailHelp { public static void Send(string subject, string body) ...
- golang:send mail using smtp package
go语言发送邮件,可以使用smtp包,两个关键函数: func PlainAuth(identity, username, password, host string) Auth func SendM ...
- Python 3.4 send mail
#coding=utf-8 #Python 3.4 https://docs.python.org/3.4/library/ #IDE:Visual Studio 2015 Window10 impo ...
- python trojan development 1st —— use python to send mail and caputre the screen then combine them
import smtplib from email.mime.text import MIMEText msg_from='1@qq.com' #发送方邮箱 passwd='bd' #填入发送方邮箱的 ...
- C# send mail with outlook and word mailmerge
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.document_members(v=office.15). ...
- Send Mail 网址
http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp http://www.c- ...
随机推荐
- Object-C中一些不同于C系列语言表现的特性
这段时间体验和学习OC,虽然这么多年基本都在使用C系列语言(C,C++,C#),但是仍然有很多的不习惯. 当然,这些不习惯不代表讨厌或者不好,也许这些就是OC作为Apple开发首选语言而显得特殊的一些 ...
- SAS零散知识总结
1,变量名命名规范:以字母或者下划线开始,可包含字母.下划线.数字,且不超过32个字符: 2,INFILE用于读取外部数据文件,一般于FILENAME(和LIBNAME用户一致,但路径要精确到文件名( ...
- 使用.net Reflector手动修改单个dll文件
在项目中修改bug会存才版本混乱的问题,加上dll中的依赖项目比较多,想要修改单个dll文件中的少量代码是很麻烦的. 可以使用Reflector和Reflexil可以手动修改单个dll文件,我使用的是 ...
- 学习django之构建Web是Meta嵌套类的几处使用
Django中meta嵌套类的使用 1.模型中使用嵌套类 在定义抽象模型时如: class Meta : abstract=true 用来指明你创建的模型是一个抽象基础类的模型继承. 2.在一个对象对 ...
- vim : 依赖: vim-common (= 2:7.3.429-2ubuntu2.1) 但是
Ubuntu 12.10 安装vim出错[日期:2013-01-18] 来源:Linux社区 作者:Cubernet [字体:大 中 小] 在Ubuntu 12.10中安装vim时出现了如下提示:正在 ...
- <<你最喜欢做什么--兴趣问题清单>>总结
二.测试作业 你最喜欢做什么--兴趣问题清单 •根据迄今为止已有的经历,你真正喜欢从事的工作是什么? 目前还没有接触工作,就工作而言,凭自己所学的本领和技术去工作,我认为我会喜欢我所做的工作 •休 ...
- c1ctf2016 wp
web: 1.web萌新福利 没啥好说的,右键查看源码得key 2.you are not admin 一看题目,就想到http头修改,常见的x-forwarded-for,referer,host, ...
- 重建Windows 8的图标缓存
Windows 8的图标缓存路径与Win7不同,重置方法如下: rem 关闭explorer.exe taskkill /f /im explorer.exe attrib -h -i %userpr ...
- 手Q兴趣号的价值在哪里
拥有5.21亿月活跃用户,如果不做点什么东西出来,实在是浪费至极.如此庞大的用户量,如果能够将内容贡献出来,那将是恐怖的,QQ空间产品就是很好的佐证. QQ群让个体用户能够连接在一起,单个的用户关系链 ...
- ORACLE 自定义分页存储过程
一.创建包 CREATE OR REPLACE PACKAGE PKG_JK_LAB_BASIC IS TYPE CURSOR_TYPE IS REF CURSOR; PROCEDURE SP_GET ...