关于powershell:向多人发送个人附件 | 珊瑚贝

Email multiple people individual attachments


我正在使用 Send-MailMessage 向多个不同的收件人发送电子邮件,每个收件人都有一个单独的报告。我刚刚使用不同的附件路径为每个收件人重复发送邮件命令,但是我遇到的问题是因为我还必须使用 -UseSsl -credential 我必须在每次发送新邮件时进行身份验证。有没有一种无需每次都验证一次的方法?

  • $creds = Get-Credential?那么你可以 Send-MailMessage … -Credential $creds 否则我不明白这个问题
  • 这是我正在做的事情: 发送邮件消息 – 到 user1@domain -From sender@domain -Subject “Report” -Body “Summary” -attachment “path of file” -smtpserver mail.mail.com -UseSsl -credential “mycredential;Send-Mailmessage -To user2@domain -From sender@domain -Subject “Report” -Body “Summary” -attachment “第二个文件路径” -smtpserver mail.mail .com -UseSsl -credential “mycredential 每次 Send-MailMessage 运行时,我都必须输入密码
  • “mycredential 是什么?那是您以前保存的变量吗?那不是正确的代码。请在问题中包含真实代码并进行编辑。


Send-MailMessage 是.net smtpclient 的package器。你可以做你的自定义版本,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$client = New-Object System.Net.Mail.SmtpClient
$client.EnableSsl = $true
$client.Host =“smtp.server.com”
$client.Credentials = $creds

foreach ($r in $recipients) {
$from =“from@mail.com”
$to = $r
$msg = New-Object System.Net.Mail.MailMessage $from, $to
$msg.Subject =“subject”
$msg.Body =“body”
$msg.Attachments.Add(“C:\\temp\\test.html”)

$client.Send($msg)
}

  • 第 1 步:(获取凭据).password | ConvertFrom-SecureString > MailPW.txt 第 2 步:$pw = Get-Content .\\\\\\\\MailPW.txt | ConvertTo-SecureString 第 3 步:$cred = New-Object System.Management.Automation.PSCredential username@domain.com, $pw 然后我可以使用变量 $cred 来避免身份验证弹出窗口。
  • 那么您是否使用上面的代码收到一些错误或弹出窗口?
  • 不,这停止了身份验证弹出。这个问题已经解决。


来源:https://www.codenong.com/54446174/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8623.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?