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:
The full path and filenames to be attached with an email.
Email addresses that you would like to send a blank carbon copy.
The actual body of the email message.
Email addresses that you would like to send a carbon copy.
An account that has permission to send the email. The default is the current user.
The email address from which the mail is sent.
The name of the SMTP server that sends the email message (For this tutorial we are using Gmail server).
The subject of the email message.
The email addresses you wish to send email to.
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 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.