博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to attach multiple files in the Send Mail Task in SSIS
阅读量:7036 次
发布时间:2019-06-28

本文共 2533 字,大约阅读时间需要 8 分钟。

Let’s say you need to create a SSIS package that creates 2 files and emails the files to someone.

Your package may look something like this:

Double-click the Send Mail Task to open the Send Mail Task Editor (shown below).

Fill in all the relevant fields, such as To, Subject, etc.

Click in the Attachments text area, and then click the “ellipsis button” to open the file dialog.  Navigate to and select the files you need. You can do this multiple times if necessary to add all the files you need.

Note that when multiple files are attached, SSIS will automatically put a vertical bar/pipe character (“|”) between each file.  However, chances are if that’s all you needed to do you would just do it via Outlook and be done.

It is likely that you need to make this dynamic, so that you can automate your process to automatically create and name your files dynamically, and then attach the files to the email.  For this, you will need to use Expressions to create your files, and to set the “FileAttachements” property.

To make your filenames dynamic, click the Expressions ellipsis in the Properties pane for the Connection Manager for the file.

Choose the “ConnectionString” property and then set the Expression in the Expression Builder.

In the example below, the current date is added to the end of the File1, so that each day when your package runs, you will have a different filename – for example, File1_20110519, File1_20110520, and so on.

So, now that you have dynamic filenames, you need to make your Send Mail task’s “FileAttachments” property dynamic.

Open the Send Mail Task editor by double clicking on the Send Mail Task.

Click the Expressions option on the left-hand side of the Task Editor.

Click in the text box to the right of Expressions and then click the “ellipsis button”.

Select the “FileAttachments” Property and then click the ellipsis button to open the Expression Builder.

So, let say you needed to attach the 2 files, File1_yyyymmdd.txt and File2_yyyymmdd.txt where yyyymmdd is the current date.

Create your Expression to be something like this:

You could have also created a package variable that stores the current date in the format yyyymmdd and use the variable instead of the long expression above. For example, if you derived the date and stored in a variable called User::TodaysDate, then your “Fileattachment” expression would look something like this:

“C:\\Projects\\File1_” + @[User::TodaysDate]  + “|” + “C:\\Projects\File2_” + @[User::TodaysDate]

转载于:https://www.cnblogs.com/qiangshu/p/5244940.html

你可能感兴趣的文章
leetcode Sort List
查看>>
开源分布式存储SeaweedFS
查看>>
Maven com.sun.jdmk:jmxtools:jar 下载不下来
查看>>
DevExpress之Skin自定义使用
查看>>
可变参数
查看>>
[日推荐]『饿了么外卖服务』饿了么官方小程序,无需下载安装!
查看>>
Maven的学习资料收集--(四)使用Maven构建Web项目-测试
查看>>
Perl:过滤注释
查看>>
51CTO技术沙龙第十六期回顾~
查看>>
Tomcat调优测试
查看>>
iptunnel配置使用
查看>>
CDH5.X安装配置kerberos认证过程
查看>>
Mac Yosemite 10.10 下利用 Launchctl 自启动 mysql
查看>>
ubuntu下的命令学习与汇总--网络管理命令
查看>>
cent os 6.4安装使用mysql
查看>>
我的友情链接
查看>>
python3.x中的urllib模块
查看>>
Spark SQL和DataFrame指南[中英对照]
查看>>
快速了解MYSQL性能优化
查看>>
python list添加元素
查看>>