Export (0) Print
Expand All

SendMailTask Class

Sends an e-mail message. This class cannot be inherited.

Namespace: Microsoft.SqlServer.Dts.Tasks.SendMailTask
Assembly: Microsoft.SqlServer.SendMailTask (in microsoft.sqlserver.sendmailtask.dll)

public sealed class SendMailTask : Task, IDTSComponentPersist, IDTSSendMailTask, IDTSBreakpointSite, 
	IDTSSuspend
public final class SendMailTask extends Task implements IDTSComponentPersist, IDTSSendMailTask, 
	IDTSBreakpointSite, IDTSSuspend
public final class SendMailTask extends Task implements IDTSComponentPersist, IDTSSendMailTask, 
	IDTSBreakpointSite, IDTSSuspend

By using the Send Mail task, a package can send notification messages when tasks in the package work flow succeed or fail. For more information, see Send Mail Task.


System.Object
   Microsoft.SqlServer.Dts.Runtime.DtsObject
     Microsoft.SqlServer.Dts.Runtime.Task
      Microsoft.SqlServer.Dts.Tasks.SendMailTask.SendMailTask

The following code sample creates, configures, and executes a new SendMailTask.

using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.SendMailTask;

class TestSendMailTask
{

  public static void Main()
  {

    Package pkg = new Package();

    ConnectionManager smtpCM;
    smtpCM = pkg.Connections.Add("SMTP");
    smtpCM.Name = "SMTP Connection Manager";
    smtpCM.ConnectionString = "smtphost";

    Executable exe = pkg.Executables.Add("STOCK:SendMailTask");
    TaskHost thSendMailTask = (TaskHost)exe;
    {
      thSendMailTask.Properties["SmtpConnection"].SetValue(thSendMailTask, "SMTP Connection Manager");
      thSendMailTask.Properties["ToLine"].SetValue(thSendMailTask, "someone1@example.com");
      thSendMailTask.Properties["CCLine"].SetValue(thSendMailTask, "someone2@example.com");
      thSendMailTask.Properties["BCCLine"].SetValue(thSendMailTask, "someone3@example.com");
      thSendMailTask.Properties["FromLine"].SetValue(thSendMailTask, "someone4@example.com");
      thSendMailTask.Properties["Priority"].SetValue(thSendMailTask, MailPriority.Normal);
      thSendMailTask.Properties["FileAttachments"].SetValue(thSendMailTask, "C:\\test_image.jpg");
      thSendMailTask.Properties["Subject"].SetValue(thSendMailTask, "Testing the SendMail Task");
      thSendMailTask.Properties["MessageSourceType"].SetValue(thSendMailTask, SendMailMessageSourceType.DirectInput);
      thSendMailTask.Properties["MessageSource"].SetValue(thSendMailTask, "This is only a test.");
    }

    DTSExecResult valResults = pkg.Validate(pkg.Connections, pkg.Variables, null, null);

    if (valResults == DTSExecResult.Success)
    {
      pkg.Execute();
    }

  }

}

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft