Send email to dynamic recipient SSIS Send Mail Task - ssis

I have an SSIS package which is going to be deployed on test, staging, and finally production.
It has a couple of "Send Mail Tasks",say 10.
As developer, I put my email address as the recipient of the email.
Currently, for the test person, I need to change all the "To"s in all the script task to e.g. "TestPerson#test.com". If following the paradigm of hard-coding the emails this way,I need to change the recipient email 30 times!!! (10 for each stage stated above)
Just wondering if there is any way to inject To field(recipient) dynamically. e.g. from a variable. like I have done for the "MessageSource"

You can set the ToLine of the Send Mail task to be the value of a variable, using an Expression from the Properties window of the task.

We use a SQL table containing a list of email recipients for various conditions (table columns of kemail, emailaddress, success, error) and set flags in the table to 0=no, 1=yes for that particular user to receive emails on particular conditions.
Then create a variable that contains a delimited list of your recipients then use an expression to set "ToLine" for the send mail task.
The only thing to watch here is that you don't end up with a no records returned from the SQL table. We always have our "support" email address always having all the bits set, to avoid this.
So the package wont need to be modified when a new user needs to receive email updates.

Related

Send HTML formatted mail from Pentaho

I need to loop through a database table and send a html formatted mail.
Nothing complex, a text value followed by a hyperlink.
I tried with xml and xsl transformation but couldn't get desired results.
ALso, advise on whether its better to construct hyperlink in PostGressql or is it okay from Pentaho
I tried with a Table Input and a Javascript step. Thing is it outputs for each row. i need to combine and concatenate each row output to form result HTML
With Pentaho: get your data with a table input, make the html (for example with a java script), get the mail parameters (addresse, attachement, etc,...) from a grid or a constant step, and give the whole to the mail step.
With the javascript you built a -tag by row named html, but you need only one message. So you group them with a Group by step (no Group field, subject=html, type=Concatenate strings separated by, value=empty). You can then drop it in the Mail step.
But the Mail step needs some more information (recipient, sender, subject, server, port,...). You can put them in the flow with a Constant step.
In view of your use-case, it may surprise you that you have to put this data in the flow rather than to feed a box in the Mail step. This is because this step is designed to send a mail personalized for each recipient.
And now that you know how to do it, refrain from sending 100000 mails to every one you can.

Dynamically attach Files to the email in SSIS

I have a requirement to send invoices as attachment to customers.
As shown in the above screenshot a table in the database contains Name of the customer and attachment name (which contains name). I need to iterate through this table and send attachment to concerned customer. These same attachments are saved in a folder. Please Help me with an approach.
As Alleman pointed out, sp_send_dbmail is the best option to go about doing the task. The only permissions that one needs to be assigned is DatabaseMailUser database role in the msdb database.
However if you feel it needs to be addressed via SSIS. Here are the steps to follow -
Create a object variable say objInvoiceAttachmentList and following three variables - sCustomerName, sAttachmentFullFilePath, sMailId
Use 'Execute SQL Task' and run a query to get the list of customers data as below. Set the result set as 'Full Result Set'. In the 'ResultSet' tab assign it to a above object variable. (Am assuming you have a column called MailId for your customers)
select name,attachment,MailId from dbo.InvoiceAttachments
Use 'For Each Loop Container'. In the 'Collection' set the enumerator as 'Foreach ADO Enumerator' and give the collection variable as objInvoiceAttachmentList. In 'Variable Mappings' tab, assign the three variables in the order of the query.
Use 'Send Mail Task' within the foreach loop task. Go to 'Expressions' and set the appropriate variables with a proper valid SMTP Connection.
It's easy in SSIS.
get the file name to a variable in SSIS
open the send mail task then go to expression.
then you can set the FileAttachment property to above variable.
You don't need to use SSIS. In fact, SSIS is really not a very good tool for this.
sp_send_dbmail can send attachments from the file system. Use the #file_attachments parameter.

Sending mail to 100 users using SSIS mail task

I have to send mails to 100 people by using SSIS send mail task. but in SSIS mail box To address text box is having 255 characters limit where it's not allowing me to do. So could you please suggest the best way to achieve this..?
Something like this:
First task (GetUnsentEmail(s)) to select Email address (stored in a table) where 'flag' = 0 and puts those records into an object variable.
The Foreach Loop Container loops through each record in that object variable and:
puts values into variables
executes the task "Send Mail Task" which uses those variables to
send the email
executes the sql task "Update send email table" which sets 'flag' to 1
I hope this help.

Export to pdf SSRS

I've some questions regarding SSRS:
I want to create Account Statements of each client
Is it possible in SSRS to do so that I will pass AccountID as a parameter for each client, and it will form and save pdf files in C drive for each AccountID. How can I automate that?
I've e-mail table of each client. Is it possible to send account statements to clients according to this e-mail list? In other words, can I query recipients of account statements and send them an e-mail with their account statements.
Thanks
If you want to do this on a regular basis, you need to utilize a feature called Data Driven Subscription.
Basically, it looks at a table(Parameter, EmailAddress) in a SQL Server.
For instance, let's say you have:
ID - Name ------ Parameter ---------------- Email
1 - SalesGuy1 - 123123123 - SalesGuy1#emailaddress.com
2 - SalesGuy2 - 111111111 - SalesGuy2#emailaddress.com
3 - SalesGuy3 - 222222222 - SalesGuy3#emailaddress.com
It then, according to this table, executes with a parameter and sends report to appropriate user.
There is no short way of describing step-by-step, so please have a look at a well-written Microsoft KB article: https://technet.microsoft.com/en-us/library/aa237461%28v=sql.80%29.aspx
There is also slightly newer version (but basically the same content):
https://msdn.microsoft.com/en-us/library/ms169673.aspx
Note: You cannot use Shared Data source with data driven subscription. You have to configure email settings inside SSRS for this to work.

Send Mail Task based on output from Execute SQL Task

How to send an email based on the ouput from the execute SQL Task in SSIS? If the query returns any results I would like to send an email if not the email should not be sent.
Do you want to send the results of the query in the mail or not?
Either way, you can do this:
Capture the number of rows returned by your query in a variable
Use an expression in your precedence constraint to send the email only if the rowcount was greater than zero
If you want the results of the query in the email, then the simplest thing is probably to write them to a flat file and then send the file as an attachment.
Alternatively, do the whole thing in a stored procedure using sp_send_dbmail and just call the procedure from your package.
It's probably a bit clunky, but you could send the results of your Execute SQL task to a variable, then use a For Loop container based on that variable. Put the Send Mail task within that For Loop container. The challange in that is only running the Send Mail once, no matter if the count is 1 or more. If your count was saved as a bool, perhaps that would work?
You could put another step in between, put in a Script Task that takes the count and returns a 0 or 1, and then use the For Loop with the Send Mail task within.
Like I said, clunky.