【问题标题】:Powershell Automated EmailPowershell 自动电子邮件
【发布时间】:2017-09-05 02:32:07
【问题描述】:

论坛新手,如果发错地方请见谅。

我正在寻找一个 powershell 脚本,它通过电子邮件发送一个包含 200 封电子邮件的列表 (.txt) 文件,该文本文件也将使用新的电子邮件地址进行更新。将发送的电子邮件正文是标准(通用)电子邮件,没有特定于每个电子邮件地址的内容。

这可能吗?

这是我目前的脚本,但它没有发送电子邮件..

$emails = @() 
      ForEach ($recipient in Get-Content "\\FILE Location")

      {
        $emails += "$recipient"
      }

$to = "TO EMAIL"
$smtp = "SMTP Server"
$from = "FROM EMAIL"
$subject = "Subject" 
$body = "EMAIL BODY"
send-MailMessage -SmtpServer $smtp -To $to -Bcc $emails -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high

提前致谢 马特。

【问题讨论】:

  • 欢迎来到 StackOverflow。如果您有一个特定的代码问题需要解决,并且您已经编写了一些您正在努力工作的代码,您通常会得到更好的帮助。查看帮助/入门页面和“如何提出好问题”指南。关于你的问题,你想看看结合Get-ContentSend-MailMessage
  • 这是我目前所拥有的...$emails = @() ForEach ($recipient in Get-Content "\\FILE Location") { $emails += "$recipient" } $ to = "TO EMAIL" $smtp = "SMTP 服务器" $from = "FROM EMAIL" $subject = "Subject" $body = "EMAIL BODY" send-MailMessage -SmtpServer $smtp -To $to -Bcc $emails -From $from -Subject $subject -Body $body -BodyAsHtml -优先级高
  • 您应该编辑您的问题以包含该问题(您应该在上方看到“编辑”链接),而不是将其放在难以阅读的评论中。
  • 抱歉,我现在已将此添加到原始问题中。谢谢。

标签: powershell


【解决方案1】:

在这些情况下,最好自己创建对象。我会这样设置:

$smtpServer = "SMTP Server"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtpCredentialsUsername = "blah@blah.com"
$smtpCredentialsPassword = ConvertTo-SecureString -String $smtpPwd -AsPlainText -Force

$Credentials = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList 
$smtpCredentialsUsername, $smtpCredentialsPassword
$smtp.Credentials = $Credentials

$msg = new-object Net.Mail.MailMessage
$msg.Body = $body
$msg.Subject = $subject
$msg.From = $from
$msg.To.ADD($to)
$msg.IsBodyHtml = $true


ForEach ($recipient in Get-Content "\\FILE Location")
  {
    $msg.Bcc.ADD($recipient)
  }

$smtp.Send($msg)

$msg.Dispose();

【讨论】:

    猜你喜欢
    • 2011-05-04
    • 1970-01-01
    • 2012-06-24
    • 2019-04-18
    • 2015-12-24
    • 2011-04-02
    • 2014-01-03
    • 2017-08-24
    • 2011-10-22
    相关资源
    最近更新 更多