Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SSIS Send SMTP Mail

Posted on 2016-09-20
2
Medium Priority
?
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Pawan Kumar earned 1000 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 13

Assisted Solution

by:Arifhusen Ansari
Arifhusen Ansari earned 1000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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.

610 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