运行以下
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.to.add("a@b.com")
$mail.Subject = "subject"
$mail.Body = "body"
$mail.save()
接收:
您不能在空值表达式上调用方法。
At line:x char:x
+ $mail.to.add("a@b.com")
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
[1]: https://i.stack.imgur.com/TqAN9.png
答案 0 :(得分:1)
$ mail的To属性似乎是一个字符串,因此您应该直接将收件人分配给它:
<link rel="stylesheet" href="https://unpkg.com/@stackoverflow/stacks/dist/css/stacks.min.css">
<!-- from https://stackoverflow.design/product/components/inputs/#appended-inputs -->
<div class="grid gs4 gsy fd-column">
<label class="grid--cell s-label">Please enter semicolon-separated post ids</label>
<div class="grid">
<div class="grid ai-center order-last s-input-fill">
<div class="grid gs4 gsx ai-center">
<button class="s-btn s-btn__primary s-btn__sm grid--cell" id="submit-ids-button" type="button">Submit</button>
</div>
</div>
<div class="grid fl1 ps-relative">
<input class="grid--cell s-input brr0" id="ids-input" type="text" placeholder="Enter ids here" />
</div>
</div>
</div>
<br/>
<div class="grid ff-column-nowrap gs4 gsy">
<label class="grid--cell s-label" for="example-item">Logs</label>
<textarea class="grid--cell s-textarea" readonly style="resize: vertical;" rows="5"></textarea>
</div>
还有一个$mail.to = "a@b.com"
属性,可用于添加多个收件人。