标签:powershell ps
#mail server configuration
$smtpServer = "发送地址SMTP"
$smtpuser = "邮件地址"
$smtpPassword = "密码"
#Create the mail message
$mail = New-Object System.Net.Mail.MailMessage
#Set the Addresses
$mailaddress = "邮件地址"
$users = @()
$users = Import-Csv -Path "c:\user.csv" 用户邮箱
foreach ($user in $users)
{
$mail.from = New-Object System.Net.Mail.MailAddress($mailaddress)
$mailtoaddress = $user.mailaddresslist
$mail.to.Add($mailtoaddress)
}
#Detection the Public IP
$ipurl = Invoke-WebRequest ‘http://myip.dnsomatic.com‘ -UseBasicParsing
$PublicIp = $ipurl.content
#set send mail
$mail.Subject = "PowerShell Detection of Demo Server for the Public Network IP Address:"
$mail.Priority = "High"
$Nowtime= get-date -Format "yyyy.MM.dd-HH.mm.ss"
$mail.Body = "日期\时间:$Nowtime 演示服务器的公网IP地址:$publicip"
#send the message
$smtp = New-Object System.Net.Mail.SmtpClient -ArgumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $smtpuser,$smtpPassword
$smtp.Send($mail)
本文出自 “百草素心” 博客,请务必保留此出处http://suxin.blog.51cto.com/535505/1650913
标签:powershell ps
原文地址:http://suxin.blog.51cto.com/535505/1650913