Integration Services Mail Task 255 character limitation

or: How to use a variable as Recipient in a SSIS Mail Task

Microsoft Integration Services (SSIS) offer a really simple mail task.

Enter a recipient, a subject and a text, configure the SMTP connection and send.

BUT! What about using a dynamic recipient list, or a To line with more than 255 characters?

Solution 1: Using Variables in Recipient list

First of all a Script Task or a SQL Task to populate your variables

Dts.Variables["User::mailTo"].Value = ",,";
Dts.Variables["User::mailCC"].Value = ",";

NOTE: Use comma to separate mail addresses instead of semicolons!

Set Properties Expression for Mail Task

Select the Mail Task, go to the properties and add expressions for your variables.

properties expressions properties expressions dialog

Solution 2: Do it all in a Script Task in C#

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net.Mail;

namespace ST_1cc4564fdaba43baa9f85c0d6b327744

    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
        String mailContent;
        String mailFrom;
        String mailTo;
        String mailSubject;
        String mailCC;
        String mailBCC;

      public void Main()

            mailContent = @"
                            Hello World,
                            This ist the mail content!
            mailFrom = "";
            mailTo = ",";
            mailCC = ",";
            mailSubject = "Mail Subject";
            mailBCC = "";

            MailMessage mail = new MailMessage(mailFrom, mailTo, mailSubject, mailContent);
            mail.CC.Add( mailCC );
            mail.Bcc.Add( mailBCC );

            SmtpClient mySmtpClient = new SmtpClient("");

            Dts.TaskResult = (int)ScriptResults.Success;

        enum ScriptResults
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure


2 Responses to “Integration Services Mail Task 255 character limitation”

    • hannes

      Hello, I’m sorry to hear that. I left the Microsoft ecosystem a few years ago so if you have an improvement please post it here.


Leave a Reply