Solved

SSIS Send SMTP Mail

Posted on 2016-09-20
2
22 Views
Last Modified: 2016-09-21
The gui in the smtp send mail task doesn't have a way to add the username and password.

What am I missing?
0
Comment
Question by:lrbrister
2 Comments
 
LVL 17

Accepted Solution

by:
Pawan Kumar Khowal earned 250 total points
Comment Utility
It does not have username and password. Chk below-

Mail Page is a place where you specify most of the configuration for your Send Mail Task.

When you create an SMTP connection manager, a dialog box similar as shown below will come up. Here you specify a meaningful name and a small description for this SMTP connection manager and then you specify the SMTP Server.

The SMTP connection manager supports only anonymous authentication and Windows authentication. It does not support basic authentication. Check "Enable Secure Socket Layer (SSL)" option if you want to encrypt communication using Secure Sockets Layer (SSL) while sending e-mail messages.

One thing to note here is if you execute your package interactively from BIDS it uses the security context of the currently logged on user, whereas if you schedule it by executing a SQL Server Agent Job then it uses the account under which SQL Server Agent is running to connect to the SMTP host.
0
 
LVL 12

Assisted Solution

by:Arifhusen Ansari
Arifhusen Ansari earned 250 total points
Comment Utility
SMTP send mail task is not that much useful in ssis.
Rather i would suggest to use custom code to send a mail.

if provide the lots of flexibility.

You should you script task for the same.

Below is the code.

I have use this code in one of my solution and just modified some of the line to explain you.
So please ignore and syntax issues.

Hope it will help you.

public void Main()
        {
            // TODO: Add your code here
            MailMessage mail = new MailMessage();
            string FilePath = Dts.Variables["ErrogLogFileFullPath"].Value.ToString();
            string ErrorPackageDetails = Dts.Variables["ErrorPackageDetails"].Value.ToString();
            string[] ErrorPackageDetailsArray = ErrorPackageDetails.Split(',');
            string SMTPServer = Dts.Variables["SMTPServer"].Value.ToString();
            string serverName = Dts.Variables["ServerName"].Value.ToString();
            int SMTPPort = Int32.Parse(Dts.Variables["SMTPPort"].Value.ToString());
            string EmailReceipientString = Dts.Variables["EmailRecipient"].Value.ToString();
            string[] EmailReceipientArray = EmailReceipientString.Split(',');
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com", 465);
            string SenderEmail = <email id used to send mail>
            string SenderEmailPass = <email password used to send mail>
            SmtpServer.Credentials = new System.Net.NetworkCredential(SenderEmail, SenderEmailPass);
            SmtpServer.EnableSsl = true;
            SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
            SmtpServer.Timeout = 30000;
            Attachment attch = new Attachment(FilePath);
            mail.From = new MailAddress(SenderEmail);
            mail.Subject = GenerateMailSubject(ErrorPackageDetailsArray, serverName);
            mail.Body = GenerateMailBody(ErrorPackageDetailsArray);
            mail.Attachments.Add(attch);
            mail.Priority = MailPriority.High;
            foreach (string EmailReceipient in EmailReceipientArray)
            {
			// This is the code to add the receipients 
                mail.To.Add(EmailReceipient);
            }
            SmtpServer.Send(mail);
            Dts.TaskResult = (int)ScriptResults.Success;
        }

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now