Add SendMail-NET file
This commit is contained in:
parent
f55b2de680
commit
ba82298014
39
.NetSendMail/SendMail-NET.ps1
Normal file
39
.NetSendMail/SendMail-NET.ps1
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user