„util/smtp-ssl-mail.ps1“ hinzufügen

This commit is contained in:
Phil 2023-03-27 11:15:11 +02:00
parent b21d8f183c
commit 54a930f5fb

28
util/smtp-ssl-mail.ps1 Normal file
View file

@ -0,0 +1,28 @@
$SMTPServer = "smtp.example.com"
$SMTPPort = 587
$SMTPUsername = "your_username"
$SMTPPassword = "your_password"
$From = "sender@example.com"
$To = "recipient@example.com"
$Subject = "Test email"
$Body = "This is a test email sent via PowerShell."
# Create the message object
$Message = New-Object System.Net.Mail.MailMessage $From, $To
$Message.Subject = $Subject
$Message.Body = $Body
$Message.IsBodyHtml = $false
# Create the SMTP client object
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword)
# Send the email
try {
$SMTPClient.Send($Message)
Write-Host "Email sent successfully!"
}
catch {
Write-Host "Error sending email: $($_.Exception.Message)"
}