Friday, September 22, 2017

PowerShell: Invoke-WebRequest Phone Arena RSS Feed Emailer

Use this code if you'd like an emailer from Phone Arena:

[xml]$phonearena = iwr "https://www.phonearena.com/feed"
$news = $phonearena.rss.channel.item
foreach ($n in $news){
$link = $n.link
$title = $n.title
$html = New-Object -ComObject "HTMLFile"
$getimglink =  ($n.description.'#cdata-section')
$html.IHTMLDocument2_write($getimglink)
$imglink = $html.body.getelementsbytagname('img')|select -expand src
$text = $html.body.innertext
$n.author = ("<table width='100%'><tr><td style='font-family: Arial, sans-serif;'><a href=$link><img width=200 align=left src=" + $imglink + "></a><center><h3>" + $title + "</h3></center></td></tr></table><table><tr><td style='font-family: Arial, sans-serif;font-size:13;'>" + $text + "</td></tr></table><hr style='border: 2px solid mintcream;'>")
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($html)|out-null
}

$body = $news.author
$body = $body.replace("???",'"')

$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "mymail@gmail.com"
$Password = "mypassword"
$to = "recipient@somemail.com"
$subject = ("Phone Arena - " + (get-date).tolongdatestring())
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $body
$message.to.add($to)
$message.from = $username
$message.IsBodyHTML = $true
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)

No comments: