Sending email using Send Email Task

  • Hi,

    How can i customize the send email task to send email only once a day instead of every time job runs

    Thanks for help

  • You can't customize the Send Mail Task to do that, but there are a number of different approaches you can take to do this.

    1) Replace the Send Mail Task in your package with a SQL task that stores any information that would have been in the email into a table with a datetime stamp. Create a second package scheduled to run once a day that retrieves the information from the table for the current date and places it in the body of the email.

    2) Keep the Send Mail Task in the package. Create a package variable that will store a date and a way to update/retrieve this value (package configuration, Execute SQL Task, etc.) Add a Script Task or a precedence constraint on the task that compares this date value to the current date, and if different, execute the Send Mail Task. Instead of using a date, you could use a flag, etc.

  • You could use an expression that evaluates the time of day and determines whether this is the correct time to execute the Send Email task. This expression could be used to set the Disable property of the task, or could be used as a constraint on the control-flow precedence arrow leading to the task, or on the Disable property of a Sequence Container containing the task, and so on.

    For debugging purposes, it would be best to use the expression to define a boolean variable, then refer to the variable in whatever property expression you decide to use. Then you can set a breakpoint and check the value of the variable before it gets to the task. Keep in mind that the Variables pane does not update the variable values at run time, you must use the Add Watch or Quick Watch panes to see them.

  • forum member (9/13/2009)


    Hi,

    How can i customize the send email task to send email only once a day instead of every time job runs

    Thanks for help

    Hello Forum Member,

    Please excuse the lateness of this resonse - I'm just geting through my backlog...

    Look into possiblly activating / deactivating the service broker queue:

    ALTER QUEUE [ExternalMailQueue] WITH ACTIVATION (

    STATUS = ON,

    PROCEDURE_NAME = [dbo].[sp_sysmail_activate],

    MAX_QUEUE_READERS = 1,

    EXECUTE AS OWNER)

    And reference (the following is not documented in my BOL, but the SP is there):

    EXEC msdb.[dbo].[sp_sysmail_activate]

    You could, perhaps run a daily job to activate the broker, then deactivate it a few minutes later?

    Hope you find a way to accomplish your goals,

    Mark
    Just a cog in the wheel.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply