„util/smtp-ssl-mail.ps1“ hinzufügen
This commit is contained in:
parent
b21d8f183c
commit
54a930f5fb
1 changed files with 28 additions and 0 deletions
28
util/smtp-ssl-mail.ps1
Normal file
28
util/smtp-ssl-mail.ps1
Normal 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)"
|
||||
}
|
Loading…
Reference in a new issue