首页 > 代码库 > 获取当前Server的公网IP地址,并邮件发送
获取当前Server的公网IP地址,并邮件发送
#mail server configuration $smtpServer = "smtp.XXXX.com" $smtpuser = "XXXX@XXXX.com" $smtpPassword = "Oa123456" #Create the mail message $mail = New-Object System.Net.Mail.MailMessage #Set the Addresses $mailaddress = "XXXX@XXXX.com" $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)
本文出自 “百草素心” 博客,请务必保留此出处http://suxin.blog.51cto.com/535505/1587513
获取当前Server的公网IP地址,并邮件发送
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。