How to send a mail using command prompt batch files

You can send an email using the command prompt and batch files using the following methods:

Method 1: Using the mail command

The mail command is a built-in command in Windows that allows you to send an email. You can use it in a batch file to send an email. Here's an example:

@echo off
set subject=Hello from batch file
set body=This is a test email sent from a batch file
set [email protected]
set [email protected]
mail -s "%subject%" -b "%body%" -f "%from%" -t "%to%"

Replace [email protected] and [email protected] with your actual email addresses.

Method 2: Using the sendmail command

The sendmail command is a third-party command-line email client that allows you to send emails. You can download it from the internet and use it in a batch file. Here's an example:

@echo off
set subject=Hello from batch file
set body=This is a test email sent from a batch file
set [email protected]
set [email protected]
sendmail -s "%subject%" -b "%body%" -f "%from%" -t "%to%"

Replace [email protected] and [email protected] with your actual email addresses.

Method 3: Using the powershell command

You can also use PowerShell to send an email using the Send-MailMessage cmdlet. Here's an example:

@echo off
powershell -Command "Send-MailMessage -Subject 'Hello from batch file' -Body 'This is a test email sent from a batch file' -From '[email protected]' -To '[email protected]'"

Replace [email protected] and [email protected] with your actual email addresses.

Method 4: Using the curl command

You can also use the curl command to send an email using a web-based email service like Gmail. Here's an example:

@echo off
set subject=Hello from batch file
set body=This is a test email sent from a batch file
set [email protected]
set [email protected]
curl -u "%from%:%password%" -X POST --data "subject=%subject%&body=%body%" https://smtp.gmail.com:587/

Replace [email protected] and [email protected] with your actual email addresses, and password with your email password.

Note: Make sure to replace the placeholders with your actual email addresses and passwords. Also, be aware of any security concerns when sending emails using batch files.