如何在 SSIS SMTP 连接管理器中指定用于简单身份验证的凭据?
How Can I Specify Credentials for Simple Authentication in SSIS SMTP Connection Manager?
我们有几个 asp.net
发送电子邮件的网络应用程序,MailMessage
对象配置了 SMTP
服务器、用户名和密码。电子邮件发送没有问题。
在 SSIS
包中,我添加了一个 SMTP 连接管理器,并配置了 smtp 服务器。我设置 UseWindowsAuthentication=True
是因为我看不到输入 username/password.
的位置
当我 运行 来自 SQL Server Agent
的包时,SSIS 正确发送了电子邮件,因此显然不需要 user/password。
那么 SMTP 包如何在没有用户凭据的情况下发送电子邮件? asp.net 也不需要凭据有意义吗?
我们都在同一个公司网络下,我们使用Exchange Server
。
谢谢。
看看这个 link。
说明该包正在使用 Sql 服务器代理帐户连接到主机。
此外,SMTP 连接管理器仅支持匿名身份验证和 Windows 身份验证。它不支持基本身份验证 - 如 documentation.
中所述
使用包含 smtp 用户和密码的字符串的参数化 ConnectionString 属性 创建 SMTP 连接管理器。
- 使用新建连接...选项创建连接select将 SMTP 作为类型。
- 在没有任何连接设置的情况下保存。给它任何你想要的名字。
- 右键单击连接并select参数化...
- Select 属性 = ConnectionString
- Select 创建新参数(例如 SMTPConnectionManager_ConnectionString)
- 将值设置为连接字符串(例如 SmtpServer=aspmx.l.google.com;port=25;UseWindowsAuthentication=False;EnableSsl=False;user=user@gmail.com;password=password123 )
- 为您的部署方法(包或项目)设置适当级别的范围。
- 点击确定
Alan Gaylor 的回答对我不起作用,但在脚本任务(而不是电子邮件任务)中执行以下操作有效:
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;
}
按照以下步骤操作
- 创建一个发送邮件任务,然后创建一个新的 smtpConnection。
- 键入您的邮件服务器名称并单击“确定”
- 右键单击 SMTP 连接管理器,然后单击参数化。
- Select 属性 列表中的 ConnectionString
- 将用户名、密码和端口添加到您的连接字符串值
SmtpServer=mail.yourServerName.com;UseWindowsAuthentication=False;EnableSsl=False;port=portnumber;user=YourUserName;Password=YourPassword;
我们有几个 asp.net
发送电子邮件的网络应用程序,MailMessage
对象配置了 SMTP
服务器、用户名和密码。电子邮件发送没有问题。
在 SSIS
包中,我添加了一个 SMTP 连接管理器,并配置了 smtp 服务器。我设置 UseWindowsAuthentication=True
是因为我看不到输入 username/password.
当我 运行 来自 SQL Server Agent
的包时,SSIS 正确发送了电子邮件,因此显然不需要 user/password。
那么 SMTP 包如何在没有用户凭据的情况下发送电子邮件? asp.net 也不需要凭据有意义吗?
我们都在同一个公司网络下,我们使用Exchange Server
。
谢谢。
看看这个 link。
说明该包正在使用 Sql 服务器代理帐户连接到主机。 此外,SMTP 连接管理器仅支持匿名身份验证和 Windows 身份验证。它不支持基本身份验证 - 如 documentation.
中所述使用包含 smtp 用户和密码的字符串的参数化 ConnectionString 属性 创建 SMTP 连接管理器。
- 使用新建连接...选项创建连接select将 SMTP 作为类型。
- 在没有任何连接设置的情况下保存。给它任何你想要的名字。
- 右键单击连接并select参数化...
- Select 属性 = ConnectionString
- Select 创建新参数(例如 SMTPConnectionManager_ConnectionString)
- 将值设置为连接字符串(例如 SmtpServer=aspmx.l.google.com;port=25;UseWindowsAuthentication=False;EnableSsl=False;user=user@gmail.com;password=password123 )
- 为您的部署方法(包或项目)设置适当级别的范围。
- 点击确定
Alan Gaylor 的回答对我不起作用,但在脚本任务(而不是电子邮件任务)中执行以下操作有效:
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;
}
按照以下步骤操作
- 创建一个发送邮件任务,然后创建一个新的 smtpConnection。
- 键入您的邮件服务器名称并单击“确定”
- 右键单击 SMTP 连接管理器,然后单击参数化。
- Select 属性 列表中的 ConnectionString
- 将用户名、密码和端口添加到您的连接字符串值
SmtpServer=mail.yourServerName.com;UseWindowsAuthentication=False;EnableSsl=False;port=portnumber;user=YourUserName;Password=YourPassword;