我有一个powershell脚本(由批处理文件调用)工作,一旦进程完成,每晚都会通过电子邮件发送日志文件。但是,由于与SMTP /身份验证相关的各种原因,我不得不使用gmail帐户发送它而不是我们的一个内部帐户交换帐户(在我的PC上运行,但基本上不在运行该进程的服务器上)。 ..
即使我将“发件人”字段作为内部电子邮件,该邮件也会从 gmail帐户到达。
任何人都可以告诉我如何强制它显示它来自内部电子邮件而不是我用来向Google验证的帐户?
谢谢!
以下是剧本:
function sendMail{
Write-Host "Sending completion email..."
#Creating SMTP server object, setting secure connection and specifying credentials
$smtpClient = new-object system.net.mail.smtpClient
$smtpClient.Host = 'smtp.gmail.com'
$smtpClient.Port = 587
$smtpClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("*gmail account*", "*gmail password*");
#Creating Email structure
$emailfrom = "*internal email*"
$emailone = "*customer email*"
$subject = "Import Process Completed"
$body = "To whom this may concern,
Your import process has completed. Attached is the import log. Please check the file and contact support if you have any questions or concerns.
Regards,
Support"
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = ($EmailFrom)
$emailMessage.To.Add($EmailOne)
$emailMessage.Subject = ($Subject)
$emailMessage.Body = ($Body)
$emailMessage.Attachments.Add("$env:TFXLog")
#Sending email
$SMTPClient.Send($emailMessage)
}
答案 0 :(得分:0)
问题是我的网络/服务器......所以上面的脚本很好,只是不在我的情况下。对于任何想知道......