【发布时间】:2020-09-15 12:28:01
【问题描述】:
我用它来发送邮件,我定义了一些包含值的包变量:
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...");
}
}
我需要向更多人发送邮件,所以我将 mailTo 设置为 mail1@gmail.com,mailBcc 为 mail2@gmail.com 并且它可以工作,但如果我将 mailBcc 设置为“mail2@gmail.com,mail3@gmail” .com" 或 "mail2@gmail.com; mail3@gmail.com" 不起作用,我该怎么做?
编辑:这是 sendMail 函数
public static void sendMail(MailProperties mailProperties, ReportETL reportETL)
{
MimeMessage message = new MimeMessage();
message.From.Add(new MailboxAddress("text..", mailProperties.fromMail));
message.To.Add(new MailboxAddress(mailProperties.toMail));
message.Subject = "text...";
if (!string.IsNullOrEmpty(mailProperties.bccMail))
{
message.Bcc.Add(new MailboxAddress(mailProperties.bccMail));
}
BodyBuilder bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = ReportETLService.getHtmlFromReporETL(reportETL);
mailProperties.pathAttachment.Where(x => File.Exists(x)).ToList().ForEach(y => bodyBuilder.Attachments.Add(y));
message.Body = bodyBuilder.ToMessageBody();
try
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.Connect(mailProperties.accountSmtp, int.Parse(mailProperties.accountSmtpPort), mailProperties.useSSL);
smtpClient.Authenticate(mailProperties.fromMail, mailProperties.accountPassword);
smtpClient.Send(message);
smtpClient.Disconnect(true);
}
catch (Exception e) { throw new Exception("text... " + e.Message); }
}
【问题讨论】:
-
您如何发送电子邮件? Sql ?第三方应用程序?或其他方式
-
@Bahtiyar 我添加了 sendMail 功能