I've noticed that alot of people have a need to send SMTP email from a script task rather than the SMTP Mail Task. A couple of the reasons for this are:
- HTML emails
- None-Windows authenticated SMTP servers
neither of which are supported by the SMTP Mail Task.
Well, its possible to use the script task as a route into using . Here's the basic code skeleton - its only really 4 lines of code. You can change it yourself to suit your requirements.
Imports
System
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.Net.Mail
Imports System.Net
Public Class ScriptMain
Public Sub Main()
Dim myHtmlMessage As MailMessage
Dim mySmtpClient As SmtpClient
myHtmlMessage=
New MailMessage(jamie.thomson@nospam.conchango.com, "jamie.thomson@nospam.conchango.com", "Subject", "body")
mySmtpClient = New SmtpClient("192.168.3.75")
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
mySmtpClient.Send(myHtmlMessage)
Dts.TaskResult = Dts.Results.Success
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
See. Dead easy!
-Jamie