【发布时间】:2020-06-02 16:04:57
【问题描述】:
当我尝试通过 powershell 发送电子邮件时,我面临以下问题 1.我无法将发件人更改为群组邮箱 2.它不会读取我添加的附件,但会发送邮件。
代码即时使用:
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = "xyz@outlook.com"
$Mail.Subject = "sql"
$mail.attachments = 'C:\Users\desktop.ini'
$Mail.Body = ""
$Mail.Send()
我收到错误:
Property is read-only.
At C:\Users\Documents\sending email.ps1:5 char:1
+ $mail.attachments = 'C:\Users\desktop.ini'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
但是文件在我的本地
【问题讨论】:
-
是否有理由使用 Outlook COM 对象而不是 Send-MailMessage?
-
当我添加 smtp 和端口详细信息时,我的 Outlook 不允许我发送电子邮件。所以尝试了像这样的替代方法
标签: powershell email outlook