How Can I Specify Credentials for Simple Authentication in SSIS SMTP Connection Manager?

百般思念 提交于 2020-07-06 11:52:58

问题


We have several asp.net web apps that send emails, and the MailMessage object is configured with an SMTP server, username and password. The emails are sent with no problems.

In an SSIS package, I added an SMTP connection manager, and I configured the smtp server. I set UseWindowsAuthentication=True because I don't see where I type in username/password.

When I run the package from SQL Server Agent, the SSIS sends the email correctly, so apparently, the user/password is not needed.

So how can the SMTP package send an email without the user credentials? Does it make sense that the asp.net don't need the credentials either?

We're all under the same company network and we use Exchange Server.

Thanks.


回答1:


Check out this link.

It explains that the package is using the Sql Server Agent account to connect to the host. Furthermore, the SMTP connection manager supports only anonymous authentication and Windows Authentication. It does not support basic authentication - as stated in the documentation.




回答2:


Create a SMTP Connection Manager with a parameterized ConnectionString property with a string which contains the smtp user and password.

  1. Create connection using New Connection... option selecting SMTP as type.
  2. Save without any connection settings. Give it any name you want.
  3. Right click the connection and select Parameterize...
  4. Select Property = ConnectionString
  5. Select Create new parameter (e.g. SMTPConnectionManager_ConnectionString)
  6. Set Value to connection string (e.g. SmtpServer=aspmx.l.google.com; port=25; UseWindowsAuthentication=False;EnableSsl=False; user=user@gmail.com; password=password123)
  7. Set scope at appropriate level for your deployment method (Package or Project).
  8. Click OK



回答3:


The answer from Alan Gaylor didn't work for me, but doing the following in a script task, not an email task, worked:

using System.Diagnostics;
using System.Net;
using System.Net.Mail;


    public void Main()
    {
        string UserName = Dts.Variables["UserName"].Value.ToString();
        string Password = Dts.Variables["Password"].Value.ToString();
        string EmailRecipient = Dts.Variables["EmailRecipient"].Value.ToString();
        string EmailSender = Dts.Variables["EmailSender"].Value.ToString();

        string SMTPEndPoint = Dts.Variables["SMTPEndPoint"].Value.ToString();
        Int32.TryParse(Dts.Variables["SMTPPort"].Value.ToString(), out int SMTPPort);

        string MessageSubject = Dts.Variables["MessageSubject"].Value.ToString();
        string MessageBody = Dts.Variables["MessageBody"].Value.ToString();

        MailMessage msg = new MailMessage();
        msg.To.Add(new MailAddress(EmailRecipient));
        msg.From = new MailAddress(EmailSender);
        msg.Subject = MessageSubject;
        msg.Body = MessageBody +
            "\n" +
            "\n" +
            "DISCLAIMER: The information contained in this transmission may contain privileged and confidential information. " +
            "It is intended only for the use of the person(s) named above.If you are not the intended recipient, " +
            "you are hereby notified that any review, dissemination, distribution or duplication of this communication " +
            "is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.";


        SmtpClient client = new SmtpClient(SMTPEndPoint, SMTPPort)
        {
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            Credentials = new NetworkCredential(UserName, Password)
        };
        try
        {
            client.Send(msg);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }
        Dts.TaskResult = (int)ScriptResults.Success;
    }


来源:https://stackoverflow.com/questions/43637009/how-can-i-specify-credentials-for-simple-authentication-in-ssis-smtp-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!