We need to send emails on success/failure of any SSIS packages. If you want to test them locally without creating the SMTP Connection or without the internet use the following tool.
Installation and configuration of SMTP4Dev:
smtp4dev is the small utility to create local mail server. Download it from the following location.
We can use the Send E-mail task only with port 25. If you can configure smtp4dev in port 25 then use Send E-mail task. otherwise use the following technique.
Mail servers are always looking for PORT 25. Look at the following screenshot[there will be error message saying “Server failure”].
Click on Options and change the port number from 25 to 26. Look at the following screenshot.
Click “Ok”
Click “Start Listening”. You will see the screen as follows.
Creating SSIS package:
Create a SSIS package. In script component, I have used the following code in the Void main() function. I used “emailMsg” variable for the body. If any changes required on the body of email can be changed outside the script component.
1: public void Main()
2: { 3: 4: var emailMsgFromSSIS = Dts.Variables["emailMsg"].Value.ToString();
5: SmtpClient client = new SmtpClient("127.0.0.1");
6: MailMessage msg = new MailMessage("From@test.com",
7: "To@test.com",
8: "Subject",
9: emailMsgFromSSIS); 10: 11: msg.IsBodyHtml = true;
12: 13: client.Credentials = CredentialCache.DefaultNetworkCredentials; 14: client.Port = 26; 15: client.Send(msg); 16: 17: // TODO: Add your code here
18: Dts.TaskResult = (int)ScriptResults.Success;
19: }
Now, package look like this.
I run the SSIS package and email message will be popped up by smtp4dev. Click view and you will see the email message[using outlook].
Thanks for reading .
-Gowdhaman