Solved

SSIS Send SMTP Mail

Posted on 2016-09-20
2
29 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 28

Accepted Solution

by:
Pawan Kumar earned 250 total points
ID: 41806855
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
ID: 41808552
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

777 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