#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 = $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)
时间: 2024-12-10 15:27:55