Scripts, Tech Random's, Tips and Tricks

Send an Email Using Command Prompt or Batch File Script with PowerShell

Apply this line to any CMD line, Run as Administrator

PowerShell.exe -NoProfile -ExecutionPolicy Bypass C:\Users\backups\Desktop\email.ps1

Then create a new text file and save it as a .PS1
-----
#this works, just sends a simple email
$smtpServer = "mail.smtp2go.com"
$smtpFrom = "FROMEMAILENTERHERE"
$smtpTo = "TOEMAILENTERHERE"
$smtpSubject = "This is my email subject"
$username = "email_username"
$password = "email_password"
$body = "yo yo yo your boat"

$smtp = New-Object -TypeName "Net.Mail.SmtpClient" -ArgumentList $smtpServer
$smtp.Credentials = New-Object system.net.networkcredential($username, $Password);
$smtpBody = "[$(Get-Date -Format HH:mm:ss)] $body"
$smtp.Send($smtpFrom, $smtpTo, $smtpSubject, $smtpBody)

-----

This email will allow you to include a subject and a body.

This post assumes you have a general understanding of what a script is, how to open CMD, and how to save txt files as .ps1.

Leave a Reply

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