我在脚本中使用Send-MailMessage
Send-MailMessage -From 'User01 <user01@fabrikam.com>' -To 'User02 <user02@fabrikam.com>', 'User03 <user03@fabrikam.com>' -Subject 'Sending the Attachment' -Body 'Forgot to send the attachment. Sending now.' -Attachments .\data.csv -Priority High -DeliveryNotificationOption OnSuccess, OnFailure -SmtpServer 'smtp.fabrikam.com'
它很好用,除非有时无法创建日志文件(因此没有附件),否则Send-MailMessage无法发送电子邮件,因为附件不存在。
我如何才能将-attachment
开关保留为Send-MailMessage
的一部分,并且即使附件失败也仍会发送电子邮件?
类似这样的内容:-Attachments (mandatory=$false)$attachment