This tutorial will help you to send an email from the Windows command line via remote SMTP server. You need SMTP server details for sending email from Windows PowerShell command.
Advertisement
Send Email from Windows PowerShell
Once you have SMTP details, open Windows PowerShell and execute the following commands one by one. You need to change the
$EmailFrom = “[email protected] ” $EmailTo = “[email protected] ” $Subject = “Email Subject Here ” $Body = “This is mail body ” $SMTPServer = “smtp.gmail.com ” $SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer,587 ) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“SMTP Username ”, “SMTP Password ”); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
This will send email to the recipient address via defined remote SMTP server. You can also write this in a PowerShell script and execute.
7 Comments
This actually works,
You however have to create an app password for you to be able to use your gmail account
It is true, the Send-MailMessage cmdlet is obsolete. Try this instead: https://sourceforge.net/projects/mail-alert/
this script does not work anymore
Exception calling “Send” with “4” argument(s): “The SMTP server requires a secure connection or the client was not
authenticated. The server response was: 5.7.0 Authentication Required. Learn more at”
WIN+R –> CMD
THEN TYPE:
start mailto:[email protected]?subject=”ANY%20SUBJECTS”
Excellent help, thank you.
Wait, what? Why wouldn’t you use the Send-MailMessage cmdlet, which was introduced in PowerShell 2.0.
Warning
The Send-MailMessage cmdlet is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage. For more information, see Platform Compatibility note DE0005.