PowerShell/Scripts/email.ps1

21 lines
519 B
PowerShell
Raw Normal View History

2020-09-29 20:05:52 +02:00
#!/snap/bin/powershell
2020-10-10 18:51:57 +02:00
2020-09-29 20:05:52 +02:00
# Syntax: ./email.ps1
# Description: sends an email
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
2020-10-05 13:12:12 +02:00
try {
$smtpServer = "smtp.example.com"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "me@example.com"
$msg.ReplyTo = "me@example.com"
$msg.To.Add("you@example.com")
$msg.subject = "Test Mail"
$msg.body = "This is a test mail."
$smtp.Send($msg)
} catch { Write-Error $Error[0] }
exit 1