uestions on Message Source Property of the Send Email Task in SSIS


  • My issues / questions

    1) When I put HTML in the Message Source property of the Send Email Task Editor in my SSIS package, the email is sent to my outlook alias. When I open it in outlook, it's not in html format, rather I see the html instead of it converting to html.  My outlook client is set to html in the properties of my client so it should be fiine.

    2) I find the Message Source area to enter the body of the email a pain. I can't return lines by clicking enter on my keyboard.  Is there another way to code this?

    3) Is there a way I can manage this using a CSS class and somehow include a css document that the Message Source can pick up?  I guess if there is another way to code the Message Source other than in the properties screen in the Send Email Task Editor such as the abilty to code this elsewhere in VS, maybe I can then reference an include somehow.

    Monday, January 09, 2006 5:05 AM

All replies

  • The SendMail task is plain text only. However one can easily code an HTML SendMail task, and this is a new topic in BOL for the Service Pack 1 release. Unfortunately it's a mess to copy the HTML from a BOL page. I'll make a note to do my best on Monday and post it for you.



    Monday, January 09, 2006 5:34 AM
  • Thanks Doug, can't wait.
    Monday, January 09, 2006 5:46 AM
  • Here is the new topic as plain text. Disappointing that it's impossible to copy and paste a BOL topic with formatting...but it is.

    Sending an HTML Mail Message with the Script Task  Send Feedback

    The Integration Services SendMail task only supports mail messages in plain text format. However you can easily send HTML mail messages by using the Script task and the mail capabilities of the .NET Framework.

    If you want to create a task that you can more easily reuse across multiple packages, consider using the code in this Script task sample as the starting point for a custom task. For more information, see Extending the Package with Custom Tasks.


    The following example uses the System.Net.Mail namespace to configure and send an HTML mail message. The script obtains the To, From, Subject, and body of the email from package variables, uses them to create a new MailMessage, and sets its IsBodyHtml property to True. Then it obtains the SMTP server name from another package variable, initializes an instance of SmtpClient, and calls its Send method to send the HTML message. The sample encapsulates the message sending functionality in a subroutine that could be reused in other scripts.

    To configure this Script Task example without an SMTP Connection Manager

    Create string variables named HtmlEmailTo, HtmlEmailFrom, and HtmlSubject and assign appropriate values to them for a valid test message.

    Create a string variable named HtmlEmailBody and assign a string of HTML markup to it. For example:

    <html><body><h1>Testing</h1><p>This is a <b>test</b> message.</p></body></html>

    Create a string variable named HtmlEmailServer and assign the name of an available STMP server that accepts anonymous outgoing messages.

    Assign all five of these variables to the ReadOnlyVariables property of a new Script task.

    Import the System.Net and System.Net.Mail namespaces into your code.

    The sample code in this topic obtains the SMTP server name from a package variable. However, you could also take advantage of an SMTP Connection Manager to encapsulate the connection information, and extract the server name from the connection manager in your code. The AcquireConnection method of the SMTP connection manager returns a string in the following format:


    You can use the String.Split method to separate this argument list into an array of individual strings at each ";" or "=", then extract the second argument (subscript 1) from the arry as the server name.

    To configure this Script Task example with an SMTP Connection Manager

    Modify the Script task configured above by removing the HtmlEmailServer variable from the list of ReadOnlyVariables.

    Replace the line of code that obtains the server name:

        Dim smtpServer As String = _

    with the following lines:

        Dim smtpConnectionString As String = _
          DirectCast(Dts.Connections("SMTP Connection Manager").AcquireConnection(Dts.Transaction), String)
        Dim smtpServer As String = _
          smtpConnectionString.Split(New Char() {"="c, ";"c})(1)

    Code Sample

    Public Sub Main()

        Dim htmlMessageTo As String = _
        Dim htmlMessageFrom As String = _
        Dim htmlMessageSubject As String = _
        Dim htmlMessageBody As String = _
        Dim smtpServer As String = _

        SendMailMessage( _
            htmlMessageTo, htmlMessageFrom, _
            htmlMessageSubject, htmlMessageBody, _
            True, smtpServer)

        Dts.TaskResult = Dts.Results.Success

      End Sub

      Private Sub SendMailMessage( _
          ByVal SendTo As String, ByVal From As String, _
          ByVal Subject As String, ByVal Body As String, _
          ByVal IsBodyHtml As Boolean, ByVal Server As String)

        Dim htmlMessage As MailMessage
        Dim mySmtpClient As SmtpClient

        htmlMessage = New MailMessage( _
          SendTo, From, Subject, Body)
        htmlMessage.IsBodyHtml = IsBodyHtml

        mySmtpClient = New SmtpClient(Server)
        mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials

      End Sub


    Monday, January 09, 2006 5:31 PM