Hi,
I am using the below code to send HTML Email body to multiple recipients and CC, its working fine. Now i have to attach multiple files in that mail. Is there any possibilities to attach multiple files with the below code else provide any other code to achieve this task.
Code:
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using System.IO;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;
namespace ST_b28025465e064c28a92afa59da1b0075.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.
To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
To open Help, press F1.
*/
public void Main()
{
// TODO: Add your code here
{
SmtpClient mySmtpClient = new SmtpClient();
MailMessage myMessage = new MailMessage();
mySmtpClient = new SmtpClient((string)Dts.Variables["User::MailSMTPServer"].Value);
// variable should contain the SMTP server configured in SQL server
mySmtpClient.Port = 25; //SMTP Port
myMessage.To.Add((string)Dts.Variables["User::to"].Value);
//Recepient�s email Address
myMessage.CC.Add((string)Dts.Variables["User::CC"].Value);
myMessage.Subject = Dts.Variables["User::subject"].Value.ToString();
//string errorMsg = Dts.Variables["User::msg"].Value.ToString();
myMessage.Body = String.Format("<HTML><body></P><P><B>Project Cost Hrs Analysis:</B><br>The MOP provides the breakup of
CGI hours and CBU hours for Finance and Accounting to make the appropriate cost allocations<br><br><b>BD Cost Hrs Analysis:</b><br>The MOP Provides analysis of BD hours entered by CGI Analysts. The entires considered are:<li>Selecting
BD option while entering TS in PMC - Region/BU is determined based on selected Slx Account CBU Book#</li><li>Some Mgmt people have BD tasks in special quarterly project 'Mgmt Leads the Way' - Region/BU is determined as defined in the tasks</li><br><br><b>Note:</b><li>The
Cost Hours are limited to timesheets entered for Oct - " + Dts.Variables["User::Prevyear"].Value.ToString() + " to " + Dts.Variables["User::MonthName"].Value.ToString() + "However the Prj Alloc Hrs shown
is for the entire project</li><li>ME, MI, AB, Awards and GC Deliverables are considered and denoted in the Type column for easy reference</li><li>TS entered for Oct -" + Dts.Variables["User::Prevyear"].Value.ToString()+ " to " + Dts.Variables["User::MonthName"].Value.ToString() + " - 2015 by a CGI resource in any of the deliverables as noted above is considered in the analysis. The completion of the projects is not checked</li><br><br><left><B>Designing
Business Through Information.</B></left><br><B>BOA</B></P></BODY></HTML>");
myMessage.IsBodyHtml = true;
myMessage.From = new MailAddress(Dts.Variables["User::from"].Value.ToString(), "BOA SERVER");
mySmtpClient.Send(myMessage);
//Send the Email
//MessageBox.Show(�Package Succedded�);
Dts.TaskResult = (int)ScriptResults.Success;
}
}
}
}