You can send an email from your Gmail account using only a single command in PowerShell. There are several ways to achieve that, however, this tutorial uses the Send-MailMessage cmdlet. Send-MailMessage cmdlet has following commonly used paramters:

Attachments string
The full path and filenames to be attached with an email.

Bcc string
Email addresses that you would like to send a blank carbon copy.

Body string
The actual body of the email message.

Cc string
Email addresses that you would like to send a carbon copy.

Credential PSCredential
An account that has permission to send the email. The default is the current user.

From string
The email address from which the mail is sent.

SmtpServer string
The name of the SMTP server that sends the email message (For this tutorial we are using Gmail server).

Subject string
The subject of the email message.

To string
The email addresses you wish to send email to.

UseSsl
Use the Secure Sockets Layer (SSL) protocol to establish a connection to the SMTP server to send email. SSL is not used by default.

Step-by-Step

Step 1. Open a notepad editor and copy the following script. Save it .ps1 extension. Replace the variables with your own desired information.

$From = "YourEmail@gmail.com"
 $To = "AnotherEmail@YourDomain.com"
 $Cc = "YourBoss@YourDomain.com"
 $Subject = "Email Subject"
 $Body = "Insert body text here"
 $SMTPServer = "smtp.gmail.com"
 $SMTPPort = "587"

Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential) -Attachments $Attachment

Step 2. Execute the script with elevated privileges.

Leave a Reply

Your email address will not be published. Required fields are marked *

*