SSIS email an attachement from a package variable

I have created an SSIS package that will produce a .csv file as an output every month, however now they want this emailed. I thought no problem, I added a send mail task. Then I attempted to add a "FileAttachments" expression from my user::strFileName variable. This only works if the file already exists. However that does not work for me because the filename actually has the date in it, so there are never 2 files with the same name. When I try to run the package with my new "send mail task" added I get an error on package validation that the "file does not exist". The file will never exist when this runs as an automated job because the file name contains the day the package ran and it only runs 1x per month. How can I get around this?
LVL 1
sqlagent007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Reza RadConsultant, TrainerCommented:
do you run your package once a month or every day?
if you run it once a month and for that specific date the file genereated, then there should be no problem, Send mail task should be able to work correctly.
but if you run every day and you want the send mail task only works when there is a file then you can check for existance of the file with a script task like this:
https://social.technet.microsoft.com/Forums/en-US/8a32c726-6067-413e-977b-b3e8b375bf22/using-ssis-to-check-if-a-flat-file-is-present?forum=sqlintegrationservices

and only direct the control flow to send mail task if the file exists. here is how you can implement such if condition with Precedence constraint to say do the second task only if the expression is returning this result;
http://www.rad.pasfu.com/index.php?/archives/11-Implement-If-condition-in-SSIS-package.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sqlagent007Author Commented:
This is great. Thank you
0
sqlagent007Author Commented:
thanks again!
0
Reza RadConsultant, TrainerCommented:
Glad it helped.
Cheers,
Reza
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.