# 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()