SendMailTask Object

DTS Programming

DTS Programming

SendMailTask Object

The SendMailTask object lets you send an e-mail as a task. For example, if you want to notify a database administrator about the success or failure of a particular task (such as a backup), you can link a SendMailTask object with a precedence constraint to the previous task. To use a SendMailTask, the computer must have the Microsoft® messaging API installed with a valid user profile.

A SendMailTask can include attached data files. You can point to a location for an attached file and send a dynamically updated file, rather than a static copy of the file fixed when you create the task. This feature is useful for sending attachments, such as log and exception files, which contain information that changes constantly, and for which the file may not exist when the package is created (at design time).

Note  If you enter an attachment file name and path that does not exist when the package is run, with some versions of the messaging API you receive the message: "Error sending mail: Internal MAPI error: the address book has no directories that contain names." This message indicates the file does not exist at the specified location, or that access permissions are not granted for the file. To fix the error, make sure that the file is available at the specified location when the package is run, or that access is granted.

Collections
Properties Collection
Properties
CCLine Property Password Property
Description Property Profile Property
FileAttachments Property SaveMailInSentItemsFolder Property
IsNTService Property Subject Property
MessageText Property ToLine Property
Name Property  

Methods
Execute Method Logon Method
GetDefaultProfileName Method ResolveName Method
InitializeMAPI Method ShowAddressBook Method
Logoff Method  

Example

The Microsoft Visual Basic® Sub SendMailMsg creates a Data Transformation Services (DTS) step and a SendMailTask object. It configures the task to send an e-mail message with attachment to a recipient named "IT Managers" and CC to "Data Center Operations":

Private Sub SendMailMsg(ByVal objPackage As DTS.Package2)
Dim objStep         As DTS.Step
Dim objTask         As DTS.Task
Dim objSendMail     As DTS.SendMailTask

'create step and task
Set objStep = objPackage.Steps.New
Set objTask = objPackage.Tasks.New("DTSSendMailTask")
Set objSendMail = objTask.CustomTask

'configure send mail task
With objSendMail
    .Name = "ErrorMailTask"
    .Profile = "Microsoft Outlook"
    .ToLine = "IT Managers"
    .CCLine = "Data Center Operations"
    .Subject = "Error in DTS Nightly Job"
    .MessageText = "An error occurred loading data " & _
                "warehouse.  See attachment for details."
    .FileAttachments = "D:\DTS_UE\Messages\DTSError.txt"
    .IsNTService = True
    .SaveMailInSentItemsFolder = True
End With

'link step to task
objStep.TaskName = objSendMail.Name
objStep.Name = "ErrorMailStep"
objPackage.Steps.Add objStep
objPackage.Tasks.Add objTask
End Sub