Sending emails through GMail using the Windows Command Line Interface (CLI) can be accomplished through two distinct methods: one utilizing PowerShell (PS1) and the other through the Command Prompt (cmd). Before proceeding, ensure you have obtained an application password for your GMail account.
PowerShell Method:
No additional software is required for this approach. Utilize the following example:
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$Subject = "PS1 email test"
$Body = "Hello there"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "AppPassword")
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
CMD:
For this, you need to download the mailsend software from https://github.com/muquit/mailsend/releases.
mailsend -to RECIPIENT@hello.com -from [email protected]^
-starttls -port 587 -auth^
-smtp smtp.gmail.com^
-sub "test" +cc +bc -v^
-user "[email protected]" -pass "AppPassword"^
-M "Hello there"
Note: Ensure you replace placeholders like "[email protected]," "[email protected]" and others with your actual email addresses. Additionally, use the correct application password obtained for your GMail account.