Featured image of post Send Gmail from curl

Send Gmail from curl

Send Gmail from curl

1. Get an App Password

https://myaccount.google.com/apppasswords Click the link above and enter an app name. Save the generated password.

2. Send an email with the curl command

Run the following command.

In the example below, the email content is written in mail.txt.

1
2
3
4
5
6
From: from@gmail.com
To: to@gmail.com
Subject: Test Email
Content-Type: text/plain; charset="UTF-8"

This is a test email.

Create the above file and run the following command.

1
curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "from@gmail.com" --mail-rcpt "to@gmail.com" --user "from@gmail.com:xxxxxxxxxxxxxxxx" --upload-file mail.txt
  • Replace xxxxxxxxxxxxxxxx with your app password.
comments powered by Disqus