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

The SendMailTask type exposes the following members.

Public methodSendMailTaskInitializes a new instance of the SendMailTask class.

Public propertyBCCLineGets or sets the e-mail addresses of the blind carbon copy recipients, delimited by semicolons when there is more than one.
Public propertyCCLineGets or sets the e-mail addresses of the carbon copy recipients, delimited by semicolons when there is more than one.
Public propertyDebugModeGets or sets a Boolean indicating whether the object is in debug mode, and whether it should raise the OnBreakpointHit event while running.
Public propertyExecutionValueReturns a user-defined object. This field is read-only. (Inherited from Task.)
Public propertyFileAttachmentsGets or sets the names of the files attached to the e-mail message, delimited by the pipe character (|) when there is more than one file.
Public propertyFromLineGets or sets the e-mail address of the sender.
Public propertyMessageSourceGets or sets the message body or the name of the source that contains the message body.
Public propertyMessageSourceTypeGets or sets a value containing the source type of the message body.
Public propertyPriorityGets or sets the priority of the message.
Public propertySmtpConnectionGets or sets the name or IP address of the Simple Mail Transfer Protocol (SMTP) server.
Public propertySubjectGets or sets the subject of the e-mail message.
Public propertySuspendRequiredGets or sets a Boolean that indicates if tasks should suspend when they encounter a breakpoint. This value is set by the runtime engine for tasks and containers when a breakpoint is encountered.
Public propertyToLineGets or sets the e-mail addresses of the recipients, delimited by semicolons if there is more than one recipient.
Public propertyVersion*** Member deprecated; see Remarks. ***   Returns the version of the task. This property is read-only. (Inherited from Task.)

Public methodAcceptBreakpointManagerPasses a BreakpointManager to the Send Mail task. This method is called by the runtime and is not used in code.
Public methodCanUpdate*** Member deprecated; see Remarks. ***   A Boolean that indicates whether the new package XML can update the old package XML. (Inherited from Task.)
Public methodEqualsDetermines whether two object instances are equal. (Inherited from DtsObject.)
Public methodExecuteExecutes the Send Mail task. (Overrides Task.Execute(Connections, VariableDispenser, IDTSComponentEvents, IDTSLogging, Object).)
Public methodGetConnectionIDGets a String containing the ID of the connection. (Inherited from Task.)
Public methodGetConnectionNameGets a String containing the name of the connection. (Inherited from Task.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from DtsObject.)
Public methodGetType (Inherited from Object.)
Public methodInitializeTaskInitializes the properties associated with the task. This method is called by the runtime and is not used in code. (Overrides Task.InitializeTask(Connections, VariableDispenser, IDTSInfoEvents, IDTSLogging, EventInfos, LogEntryInfos, ObjectReferenceTracker).)
Public methodLoadFromXMLThis method is not callable by your application code. To load a package saved as .xml, use the Application.LoadPackage method.
Public methodResumeExecutionResumes execution of the task after pausing. The task or container is resumed by the runtime engine.
Public methodSaveToXMLThis method is not callable by your application code. To save a package as .xml, use the Application.SaveToXml method.
Public methodSuspendExecutionIndicates that the executable needs to suspend. This method is called by the runtime engine.
Public methodToString (Inherited from Object.)
Public methodUpdate*** Member deprecated; see Remarks. ***   This method updates the old package XML with the new package XML if CanUpdate is set to true. (Inherited from Task.)
Public methodValidateVerifies that the task is properly configured. (Overrides Task.Validate(Connections, VariableDispenser, IDTSComponentEvents, IDTSLogging).)

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.

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)



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

Community Additions

© 2015 Microsoft