This article takes 163 mailboxes as an example, describes how to send messages using PowerShell, the following is the script content.
# Restore PowerShell's default execution policy, which does not allow any scripts to be executed by default
# Set-executionpolicy Default-force
#设置Powershell的执行策略为, you can execute any script
# Set-executionpolicy Unrestricted-force
#定义一个发送邮件的函数sendEmail (recipient address, sender address, mail server, mail server port, mail server login password, mail header, message body)
Function SendEmail ([string] $to, [string] $from, [string] $smtpServer, [int] $port, [string] $password, [string] $subjet, [ String] $body)
{
#生成一个. NET mail client object, parameter is the address and port of the server
$SMTPClient = New-object Net.Mail.SmtpClient ($SmtpServer, 25)
#使用SSL加密
$SMTPClient. Enablessl = $true
#提供邮件客户端类使用的用户名和密码
$SMTPClient. Credentials = New-object System.Net.NetworkCredential ($from, $password)
#调用send方法发送邮件
$SMTPClient. Send ($from, $to, $Subject, $Body)
}
#调用方式
SendEmail "Recipient email Address" "Sender email Address" "smtp.163.com" 25 "password" "Mail Header" "Message body"
This article from the "Secret Flying Tiger Space" blog, declined to reprint!
Send mail using PowerShell