Skip to content

Instantly share code, notes, and snippets.

@dimiboy
Last active September 17, 2021 19:42
Show Gist options
  • Save dimiboy/094c26b90e74a98675ce6b7cd25b907b to your computer and use it in GitHub Desktop.
Save dimiboy/094c26b90e74a98675ce6b7cd25b907b to your computer and use it in GitHub Desktop.
# https://youtube.com/c/dimustech
# https://youtube.com/c/dimustechil
param(
[switch] $mail,
[switch] $baloon,
[switch] $telegram,
[Parameter(Mandatory)]
[string]$subject,
[string]$body = $subject
)
# Mail settings:
$MailFrom = "myoutlook@outlook.com"
$SmtpServer = "smtp-mail.outlook.com"
$MailPass = "MYPASSWORD"
$mailTo = "mymail@mail.com"
$mailPort = "587"
# Telegram Settings:
$MyToken = ""
$ChatID = ""
if($mail){
$secpasswd = ConvertTo-SecureString $MailPass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($MailFrom, $secpasswd)
Send-MailMessage -From $MailFrom -SmtpServer $SmtpServer -Credential $cred -subject $subject -body $body -to $mailTo -port $mailPort -usessl
}
if($baloon){
Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Info
$balmsg.BalloonTipText = $body
$balmsg.BalloonTipTitle = $subject
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(100000)
}
if($telegram){
if ($subject -ne $body){
$message = $subject
Invoke-RestMethod -Uri "https://api.telegram.org/bot$($MyToken)/sendMessage?chat_id=$($chatID)&text=$($Message)&parse_mode=html"
}
$message = $body
Invoke-RestMethod -Uri "https://api.telegram.org/bot$($MyToken)/sendMessage?chat_id=$($chatID)&text=$($Message)&parse_mode=html"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment