Send email gmail powershell

You can use the Send-MailMessage cmdlet in PowerShell to send an email using your Gmail account. Here's an example:

$from = "[email protected]"
$to = "[email protected]"
$subject = "Test email from PowerShell"
$body = "This is a test email sent from PowerShell using Gmail."

$smtpServer = "smtp.gmail.com"
$smtpPort = 587

$cred = New-Object System.Net.NetworkCredential($from, (ConvertTo-SecureString "your-gmail-password" -AsPlainText -Force))

Send-MailMessage -From $from -To $to -Subject $subject -Body $body -SmtpServer $smtpServer -Port $smtpPort -Credential $cred

Make sure to replace the placeholders with your actual Gmail username, password, and recipient email address.

Note:

Also, you can use the Send-Gmail module which is a PowerShell module that allows you to send emails using Gmail. You can install it by running the following command:

Install-Module -Name Send-Gmail

Then you can use the following command to send an email:

Send-Gmail -From "[email protected]" -To "[email protected]" -Subject "Test email from PowerShell" -Body "This is a test email sent from PowerShell using Gmail."

Make sure to replace the placeholders with your actual Gmail username and password.