c#向多个收件人发送邮件
我使用它发送邮件,我定义了一些包变量,其中包含值:c#向多个收件人发送邮件,c#,ssis,mailkit,C#,Ssis,Mailkit,我使用它发送邮件,我定义了一些包变量,其中包含值: public MailProperties(ScriptObjectModel dts) { if ( !string.IsNullOrEmpty((string)dts.Variables["$Package::mailFrom"].Value) && !string.IsNullOrEmpty((string)dts.Variable
public MailProperties(ScriptObjectModel dts)
{
if (
!string.IsNullOrEmpty((string)dts.Variables["$Package::mailFrom"].Value) &&
!string.IsNullOrEmpty((string)dts.Variables["$Package::mailTo"].Value) &&
!string.IsNullOrEmpty((string)dts.Variables["$Package::mailPwd"].GetSensitiveValue()) &&
!string.IsNullOrEmpty((string)dts.Variables["$Package::mailSmtp"].Value) &&
!string.IsNullOrEmpty((string)dts.Variables["$Package::mailPort"].Value)
)
{
fromMail = (string)dts.Variables["$Package::mailFrom"].Value;
toMail = (string)dts.Variables["$Package::mailTo"].Value;
bccMail = (string)dts.Variables["$Package::mailBcc"].Value;
accountPassword = (string)dts.Variables["$Package::mailPwd"].GetSensitiveValue();
accountSmtp = (string)dts.Variables["$Package::mailSmtp"].Value;
accountSmtpPort = (string)dts.Variables["$Package::mailPort"].Value;
useSSL = (bool)dts.Variables["$Package::useSSL"].Value;
pathAttachment = new List<string>();
pathAttachment.Add((string)dts.Variables["User::pathFileReject"].Value);
pathAttachment.Add((string)dts.Variables["User::pathFileReject2"].Value);
}
else
{
throw new Exception("error text...");
}
}
不使用密件抄送(这是一个选项,但存在最大计数的问题),只需迭代所有邮件地址并为每个收件人发送一个即可。(不要太快,否则会有其他问题)
通过这种方式,应该“更容易”发现无法送达的邮件。根据文档
消息。to
是列表类型。因此,您可以添加更多类似这样的地址
InternetAddressList list = new InternetAddressList();
list.add(adress1)
list.add(adress2)
list.add(adress3)
list.add(adress4)
message.To.AddRange(list);
好吧,假设您的
toMail
、ccMail
和bccMail
属性只是字符串,而不是字符串列表,您可以这样做:
InternetAddressList list;
if (!string.IsNullOrEmpty(mailProperties.toMail) && InternetAddressList.TryParse (mailProperties.toMail, out list))
message.To.AddRange(list);
if (!string.IsNullOrEmpty(mailProperties.ccMail) && InternetAddressList.TryParse (mailProperties.ccMail, out list))
message.Cc.AddRange(list);
if (!string.IsNullOrEmpty(mailProperties.bccMail) && InternetAddressList.TryParse (mailProperties.bccMail, out list))
message.Bcc.AddRange(list);
你如何发送电子邮件?Sql?第三方应用程序?还是别的way@Bahtiyar我添加了sendMail功能,这是否回答了您的问题?
InternetAddressList list;
if (!string.IsNullOrEmpty(mailProperties.toMail) && InternetAddressList.TryParse (mailProperties.toMail, out list))
message.To.AddRange(list);
if (!string.IsNullOrEmpty(mailProperties.ccMail) && InternetAddressList.TryParse (mailProperties.ccMail, out list))
message.Cc.AddRange(list);
if (!string.IsNullOrEmpty(mailProperties.bccMail) && InternetAddressList.TryParse (mailProperties.bccMail, out list))
message.Bcc.AddRange(list);