Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Windows Tutorials»How To Send Email From Windows Command Line

    How To Send Email From Windows Command Line

    By RahulApril 3, 20191 Min Read

    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 orange highlighted values with the appropriate values as per your setup.

    $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.

    Email PowerShell windows
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    4 Methods to Check .NET Framework Version on Windows

    Generate the SSH Key Pair on Windows {5 Steps}

    How to Clear the ASP.NET Temporary files in Windows

    View 7 Comments

    7 Comments

    1. David on November 8, 2022 5:59 pm

      This actually works,
      You however have to create an app password for you to be able to use your gmail account

      Reply
    2. Adam on August 12, 2022 12:16 am

      It is true, the Send-MailMessage cmdlet is obsolete. Try this instead: https://sourceforge.net/projects/mail-alert/

      Reply
    3. egon on December 23, 2019 8:51 pm

      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”

      Reply
    4. Julien Béliveau on June 6, 2019 5:53 pm

      WIN+R –> CMD
      THEN TYPE:
      start mailto:[email protected]?subject=”ANY%20SUBJECTS”

      Reply
    5. Dikshit on April 25, 2019 8:48 am

      Excellent help, thank you.

      Reply
    6. Tim on April 3, 2019 12:12 pm

      Wait, what? Why wouldn’t you use the Send-MailMessage cmdlet, which was introduced in PowerShell 2.0.

      Reply
      • Raffael on September 30, 2021 7:58 am

        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.

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.