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]

最新文章

  1. 更换域名后的数据库sql的执行命令
  2. redis迁移工具-redis-migrate-tool使用测试
  3. Android NDK开发
  4. Java 线程 — synchronized、volatile、锁
  5. Nginx一致性哈希模块的Lua实现
  6. springMVC框架下——通用接口之图片上传接口
  7. 2064: 分裂 - BZOJ
  8. CF 353C Find Maximum #205 (Div. 2)
  9. windows下安装ubantu
  10. WebFormJS注册位置
  11. Linux/UNIX套接字连接
  12. 转载:如何查看用户当前shell和修改用户登陆时的默认shell
  13. javascript7
  14. node.js + mongodb
  15. salt-stack部署
  16. [转载] Gossip算法学习
  17. CASE WHEN 高阶用法?
  18. python基础(数组)
  19. 【ES】学习1-入门使用
  20. Leetcode 22

热门文章

  1. 解决postgresql在docker中无法保存状态的问题
  2. Ubuntu18.04下更改apt源为阿里云源
  3. 集合比较器报错java.lang.IllegalArgumentException: Comparison method violates its general contract!
  4. JavaScript动态创建script标签并执行js代码
  5. @JsonView注解指定返回的model类中显示的字段
  6. PCL智能指针疑云 <三> 智能指针作为函数的传值参数和传引用参数
  7. D. Print a 1337-string...
  8. Mysql中 BLOB字段转String的方法
  9. 测试常用shell语句——数值,数组类型;函数创建
  10. SpringBoot 优雅的整合 Shiro