Send-MailMessage
傳送電子郵件訊息。
語法
Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {<None> | <OnSuccess> | <OnFailure> | <Delay> | <Never>}] [-Encoding <Encoding>] [-Priority {<Normal> | <Low> | <High>}] [-UseSsl] [<CommonParameters>]
描述
Send-MailMessage Cmdlet 會從 Windows PowerShell 內傳送電子郵件訊息。
參數
-Attachments <string[]>
指定要在電子郵件訊息中附加之檔案的路徑和檔名。您可以直接使用此參數,或經由管道將路徑和檔名輸出至 Send-MailMessage。
必要? |
false |
位置? |
named |
預設值 |
|
接受管線輸入? |
true (ByValue) |
接受萬用字元? |
false |
-Bcc <string[]>
指定接收郵件副本但不列為訊息收件者的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Body <string>
指定電子郵件訊息的內文 (內容)。
必要? |
false |
位置? |
3 |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-BodyAsHtml
表示 Body 參數的值包含 HTML。
必要? |
false |
位置? |
named |
預設值 |
False |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Cc <string[]>
指定要傳送電子郵件訊息副本 (CC) 至的電子郵件地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Credential <PSCredential>
指定具有執行此動作之權限的使用者帳戶。預設為目前使用者。
請輸入使用者名稱,例如 "User01" 或 "Domain01\User01"。或者輸入 PSCredential 物件,例如 Get-Credential Cmdlet 所傳回的物件。
必要? |
false |
位置? |
named |
預設值 |
目前使用者 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-DeliveryNotificationOption <DeliveryNotificationOptions>
指定電子郵件訊息的傳遞通知選項。您可以指定多個值。預設值為 "None"。此參數的別名為 "dno"。
傳遞通知會以電子郵件訊息傳送到 To 參數值中所指定的地址。
有效的值包括:
-- None:沒有通知。
-- OnSuccess:如果傳遞成功則發送通知。
-- OnFailure:如果傳遞失敗則發送通知。
-- Delay:如果傳遞延遲則發送通知。
-- Never:永不通知。
必要? |
false |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Encoding <Encoding>
指定用於內文和主旨的編碼。有效的值包括 ASCII、UTF8、UTF7、UTF32、Unicode、BigEndianUnicode、Default 和 OEM。預設為 ASCII。
必要? |
false |
位置? |
named |
預設值 |
ASCII |
接受管線輸入? |
false |
接受萬用字元? |
false |
-From <string>
指定郵件傳送的來源地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。
必要? |
true |
位置? |
named |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Priority <MailPriority>
指定電子郵件訊息的優先順序。此參數的有效值包括 Normal、High 和 Low。預設為 Normal。
必要? |
false |
位置? |
named |
預設值 |
Normal. |
接受管線輸入? |
false |
接受萬用字元? |
false |
-SmtpServer <string>
指定傳送電子郵件訊息的 SMTP 伺服器名稱。
預設值為 $PSEmailServer 喜好設定變數的值。如果未設定該喜好設定變數,而且省略此參數,則命令會失敗。
必要? |
false |
位置? |
4 |
預設值 |
$PSEmailServer |
接受管線輸入? |
false |
接受萬用字元? |
false |
-Subject <string>
指定電子郵件訊息的主旨。此參數為必要項。
必要? |
true |
位置? |
2 |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-To <string[]>
指定郵件傳送的目標地址。請輸入姓名 (選擇性) 和電子郵件地址,例如「姓名 <someone@example.com>」。此參數為必要項。
必要? |
true |
位置? |
1 |
預設值 |
無 |
接受管線輸入? |
false |
接受萬用字元? |
false |
-UseSsl
使用安全通訊端層 (SSL) 通訊協定來建立遠端電腦的連線,以便傳送郵件。根據預設,系統不會使用 SSL。
必要? |
false |
位置? |
named |
預設值 |
False |
接受管線輸入? |
false |
接受萬用字元? |
false |
<CommonParameters>
這個 Cmdlet 支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_Commonparameters.
輸入和輸出
輸入型別是可經由管道輸出至 Cmdlet 的物件型別。傳回型別則是 Cmdlet 所傳回的物件型別。
輸入 |
System.String 您可經由管道將附件的路徑和檔名輸出至 Send-MailMessage。 |
輸出 |
無 這個 Cmdlet 不會產生任何輸出。 |
範例 1
C:\PS>send-mailmessage -to "User01 <user01@example.com>" -from "User02 <user02@example.com>" -subject "Test mail"
描述
-----------
這個命令會從 User01 傳送一封電子郵件訊息給 User02。
這封電子郵件訊息有必要的主旨,但沒有選擇性的內容。此外,由於未指定 SmtpServer 參數,Send-MailMessage 會為 SMTP 伺服器使用 $PSEmailServer 喜好設定變數的值。
範例 2
C:\PS>send-mailmessage -from "User01 <user01@example.com>" -to "User02 <user02@example.com>", "User03 <user03@example.com>" -subject "Sending the Attachment" -body "Forgot to send the attachment. Sending now." -Attachment "data.csv" -priority High -dno onSuccess, onFailure -smtpServer smtp.fabrikam.com
描述
-----------
這個命令會從 User01 傳送一封有附件的電子郵件訊息給其他兩位使用者。
它會指定優先順序值為 "High",並要求在電子郵件訊息已經傳遞時或失敗時以電子郵件傳遞通知。
範例 3
C:\PS>send-mailmessage -to "User01 <user01@example.com>" -from "ITGroup <itdept@example.com>" -cc "User02 <user02@example.com>" -bcc ITMgr <itmgr@example.com> -subject "Don't forget today's meeting!" -credential domain01\admin01 -useSSL
描述
-----------
這個命令會從 User01 傳送一封電子郵件訊息給 ITGroup 郵寄清單,同時將副本 (CC) 寄給 User02,以及將密件副本 (BCC) 寄給 IT 主管 (ITMgr)。
這個命令會使用網域系統管理員的認證和 UseSSL 參數。