提问人:Gray Meiring 提问时间:11/15/2023 更新时间:11/15/2023 访问量:12
通过 SMTP 从 PowerShell 通过电子邮件发送 Excel 附件
Email Excel attachment from PowerShell via SMTP
问:
我是 PowerShell 的新手。我写了一个简单的电子邮件脚本,它确实有效。但是,我需要进一步修改它以包含 Excel 文档作为附件。
假设文件位置是 C:\DocFolder,文件名是 doc.xlsx
请有人可以协助添加功能以通过电子邮件发送附件吗?我的脚本如下:
# Define email parameters
$smtpServer = "[email protected]"
$smtpPort = 25
$from = "[email protected]"
$to = "[email protected]"
$subject = "Test Email"
$body = "Testing 123"
$smtpUsername = "[email protected]"
$smtpPassword = "mypassword"
# Create the email message
$message = @{
To = $to
From = $from
Subject = $subject
Body = $body
SmtpServer = $smtpServer
Port = $smtpPort
Credential = New-Object System.Management.Automation.PSCredential ($smtpUsername,
(ConvertTo-SecureString $smtpPassword -AsPlainText -Force))
UseSsl = $false # Use SSL for secure communication (set to $true for TLS)
}
# Send the email
Send-MailMessage @message
谢谢
答: 暂无答案
评论