Add SendMail-NET file

This commit is contained in:
Tomasz Kostrzewa 2024-05-01 20:51:37 +02:00
parent f55b2de680
commit ba82298014

View File

@ -0,0 +1,39 @@
# gitea.RdzeN.net
# e-mail sending with .Net
# gmail example:
$smtpServer = "smtp.gmail.com"
$smtpPort = 587
$smtpUsername = "GmailUsername"
$smtpPassword = "GmailAppPassword" # URL to generate https://myaccount.google.com/apppasswords
$from = "EmailFrom"
$to = "EmailTo"
$subject = "Example 01"
$bodyHtml = @"
Example message
"@
# Message
$message = New-Object System.Net.Mail.MailMessage
$message.From = $from
$message.Subject = $subject
$message.Body = $bodyHtml
$message.IsBodyHtml = $true
$message.To.Add($to) # Add method because of 'To' is a ReadOnly property.
# Smtp
$smtp = New-Object System.Net.Mail.SmtpClient($smtpServer, $smtpPort)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($smtpUsername, $smtpPassword)
# Send message
$smtp.Send($message)
# Details
#$message | select *
#$smtp | select *
# Dispose Message/Smtp
$message.Dispose()
$smtp.Dispose()