powershell - 无法使用 PowerShell 脚本发送电子邮件
问题描述
我无法使用以下脚本发送电子邮件
$fromemail = "pap@domainname.com"
$users = "pap@domainname.com"
$Server = "smptserver.domainname.com"
Send-MailMessage -From $fromemail -To $users -Subject "Disk Space Monitoring Report" -Body "Hello world" -Priority High -SmtpServer $server
这是输出屏幕下方显示的错误消息:
Send-MailMessage :无法解析远程名称: 'smptserver.domainname.com' 在行:10 字符:2 + Send-MailMessage -From $fromemail -To $users -Subject "Disk Space Mo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException + FullyQualifiedErrorId:SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
解决方案
认为您需要将变量写为字符串还使用 smtp 服务器的 ip 地址而不是 dns 名称
> [string]$stmp = 0.0.0.0
[string]$emailfrom = email@company.com
> [string]$emailtoo = email@company.com (if you add more than one email
> address here add a [] at the end of string like so [string[]]$emailtoo)
推荐阅读
- tensorflow - 我安装了 tensforflow 并使用了该命令,但它显示以下错误
- react-native - 基于ajax调用在底部导航器中动态显示堆栈
- gitlab - 如何从 .net 项目文件中获取 gitlab-ci.yml 文件中的项目版本?
- android - 无法在片段中显示来自 Firestore 的回收视图项目
- php - Laravel:上传 64base 图像而不是普通图像
- cors - 如何在 Keycloak 中禁用 CORS
- python - 用上一个/下一个值 +- 100 在列中填充 Na
- python - 您能帮助理解 OR 运算符在此代码中的工作原理吗?
- reactjs - 好像不知道saga run方法
- sql - 查询优化(使用连接而不是子查询)?