Home » Questions » Computers [ Ask a new question ]

Send Email via Gmail from Command Prompt

Send Email via Gmail from Command Prompt

I've got some backup jobs running weekly and would like to have the log files sent to me automatically via email so I don't have to manually check them.

Asked by: Guest | Views: 281
Total answers/comments: 2
Guest [Entry]

"Gmail can be used for sending mail by any mail program and from any network.

Some command-line mail products for Windows are:

SendEmail
mailsend
(I have no first-hand experience with these products.)

See also this article : How to use Gmail as your SMTP server."
Guest [Entry]

"HowToGeek demonstrates a Windows PowerShell script that works very well at How To Send Email From the Command Line in Windows Without Extra Software

Here is the method:
First you're defining the variables:

$EmailFrom = “yourMail@gmail.com”
$EmailTo = “theRecipient'sAddress@someServer.com”
$Subject = “your subject”
$Body = “some text”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“yourGmailUsername”, “password”);

Then, you're using this command to send the mail:

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

You'll need a valid Gmail account in order to authenticate as a Gmail user."