#mail server configuration$smtpServer = SMTP. Xxxx.com "$smtpuser = " [email protected] "$smtpPassword = " Oa123456 "#Create the mail message $mail = New-Object System.Net.Mail.MailMessage#Set the addresses$mailaddress = "[email protected]" $users = @ () $users = import-csv -Path "C:\user.csv" foreach ($user in $users) { # $user = $users -split ', ' $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 =&nbSP; $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 = "date \ Time: $Nowtime Demo Server's public IP address: $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)
This article is from the "Paraquat Susan" blog, so be sure to keep this source http://suxin.blog.51cto.com/535505/1587513
Gets the current server's public IP address and sends the message