Solved

SSIS Send SMTP Mail

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

911 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

25 Experts available now in Live!

Get 1:1 Help Now