PowerShell Management Series (34) Send-mailmessage of PowerShell operations

Source: Internet
Author: User
Tags mailmessage

-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750

For administrators, it is often necessary to test the service running status of the online system, and PowerShell's Send-mailmessage command is used more frequently, with the following commands:

1, Send-mailmessage-from [email protected]-to "[email protected]"-subject "test"-credential "[email protected]"-smtpse RVer Mail.yuntcloud.com-port 587

650) this.width=650; "Width=" 502 "height=" "title=" QQ picture 20161011222408.png "style=" width:722px;height:160px; "src=" Http://s1.51cto.com/wyfs02/M01/88/9D/wKiom1f89hihqPcXAAAxmHUVeQY182.png-wh_500x0-wm_3-wmp_4-s_2075506624.png " alt= "Wkiom1f89hihqpcxaaaxmhuveqy182.png-wh_50"/>


2, send Chinese characters when the message will appear character garbled, we need to add parameter-encoding ([System.text.encoding]::utf8)

Send-mailmessage-from [email protected]-to "[email protected]"-subject "test"-credential "[email protected]"-smtpserv ER mail.yuntcloud.com-port 587-encoding ([System.text.encoding]::utf8)


3, we can convert this password to ciphertext password to save, for PowerShell direct call, the command is as follows:

$UserName = "[email protected]" #定义管理员账户名称
$Password = convertto-securestring Aa543cd-asplaintext–force
$cred = New-object System.Management.Automation.PSCredential ($UserName, $Password)
Send-mailmessage-from [email protected]-to "[email protected]"-subject "test"-credential $cred-smtpserver MAIL.YUNTCL Oud.com-port 587-encoding ([System.text.encoding]::utf8)


4. Send an e-mail with an attachment
$NMSG = "
<br> Hello! </br>
<br> attachment is the user Mailbox status report for your business:</br>
<b><br> This is an automatic message sent by the system, please do not reply or forward this email directly. </br></b>
<br> have any questions please contact <a Href=mailto:[email protected]> Professional Technical Support </a></br>
"

$date = Get-date #获取当前日期
$nSmtpserver = "Mail.yuntcloud.com"
$nFrom = "[Email protected]"
$nTo = "[Email protected]"
$nSubject = "Latest usage of Enterprise mailbox users, $date"

$UserName = "[email protected]" #定义管理员账户名称
$Password = convertto-securestring Aa543cd-asplaintext–force
$cred = New-object System.Management.Automation.PSCredential ($UserName, $Password)

Send-mailmessage-bodyashtml-subject $nSubject-smtpserver $nSmtpserver-from $nFrom-to $nTo-body $nMsg-attachments (" The latest usage of C: \ Enterprise user mailbox. csv "," the latest usage of the C: \ Enterprise Archive mailbox. csv ") -credential $cred-smtpserver mail.yuntcloud.com-port 587-encoding ( [System.text.encoding]::utf8]

Write-host "completed, the latest usage of Enterprise Mailbox user and archive mailbox has been sent to $nTo"



This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1860876

PowerShell Management Series (34) Send-mailmessage of PowerShell operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.