代码
Public Sub Main()
Dim htmlMessageTo As String = _
Dts.Variables("HtmlEmailTo").Value.ToString
Dim htmlMessageFrom As String = _
Dts.Variables("HtmlEmailFrom").Value.ToString
Dim htmlMessageSubject As String = _
Dts.Variables("HtmlEmailSubject").Value.ToString
Dim htmlMessageBody As String = _
Dts.Variables("HtmlEmailBody").Value.ToString
Dim smtpServer As String = _
Dts.Variables("HtmlEmailServer").Value.ToString
SendMailMessage( _
htmlMessageTo, htmlMessageFrom, _
htmlMessageSubject, htmlMessageBody, _
True, smtpServer)
Dts.TaskResult = ScriptResults.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
mySmtpClient.Send(htmlMessage)
End Sub
public void Main()
{
string htmlMessageTo = Dts.Variables["HtmlEmailTo"].Value.ToString();
string htmlMessageFrom = Dts.Variables["HtmlEmailFrom"].Value.ToString();
string htmlMessageSubject = Dts.Variables["HtmlEmailSubject"].Value.ToString();
string htmlMessageBody = Dts.Variables["HtmlEmailBody"].Value.ToString();
string smtpServer = Dts.Variables["HtmlEmailServer"].Value.ToString();
SendMailMessage(htmlMessageTo, htmlMessageFrom, htmlMessageSubject, htmlMessageBody, true, smtpServer);
Dts.TaskResult = (int)ScriptResults.Success;
}
private void SendMailMessage(string SendTo, string From, string Subject, string Body, bool IsBodyHtml, string Server)
{
MailMessage htmlMessage;
SmtpClient mySmtpClient;
htmlMessage = new MailMessage(SendTo, From, Subject, Body);
htmlMessage.IsBodyHtml = IsBodyHtml;
mySmtpClient = new SmtpClient(Server);
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
mySmtpClient.Send(htmlMessage);
}
使 Integration Services 保持最新
若要从 Microsoft 获得最新的下载内容、文章、示例和视频,以及从社区获得所选解决方案,请访问 MSDN 或 TechNet 上的 Integration Services 页:
若要获得有关这些更新的自动通知,请订阅该页上提供的 RSS 源。