Skip to content

Instantly share code, notes, and snippets.

View dans6887's full-sized avatar
💭
I may be slow to respond.

DrSundae dans6887

💭
I may be slow to respond.
View GitHub Profile
@dans6887
dans6887 / Send-EmailViaGmail.ps1
Created November 12, 2025 20:10 — forked from tillig/Send-EmailViaGmail.ps1
Send an email via the Gmail SMTP server using Powershell
$From = "your-gmail-address@gmail.com"
$To = "the-destination-user@domain.com"
$Subject = "Email subject goes here"
$Body = "Email body goes here"
# The password is an app-specific password if you have 2-factor-auth enabled
$Password = "app-specific-password-here" | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "smtp.gmail.com" -port 587 -UseSsl -Credential $Credential