Send mail using PowerShell

Source: Internet
Author: User
Tags server port smtpclient

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

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.