Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using curl to send email

How can I use the curl command line program to send an email from a gmail account?

I have tried the following:

curl -n --ssl-reqd --mail-from "<[email protected]>" --mail-rcpt "<[email protected]>" --url smtps://smtp.gmail.com:465 -T file.txt 

With file.txt being the email's contents, however, when I run this command I get the following error:

curl: (67) Access denied: 530 

Is it possible to send an email from an account that is hosted by a personal server, still using curl? Does that make the authentication process easier?

like image 929
NSNolan Avatar asked Feb 06 '13 05:02

NSNolan


People also ask

How do you send attachments with curl?

Posting a File with Curl. To post a file with Curl, use the -d or -F command-line options and start the data with the @ symbol followed by the file name. To send multiple files, repeat the -F option several times.

What is curl command?

Client URL (cURL, pronounced “curl”) is a command line tool that enables data exchange between a device and a server through a terminal. Using this command line interface (CLI), a user specifies a server URL (the location where they want to send a request) and the data they want to send to that server URL.


2 Answers

curl --ssl-reqd \   --url 'smtps://smtp.gmail.com:465' \   --user '[email protected]:password' \   --mail-from '[email protected]' \   --mail-rcpt '[email protected]' \   --upload-file mail.txt 

mail.txt file contents:

From: "User Name" <[email protected]> To: "John Smith" <[email protected]> Subject: This is a test  Hi John, I’m sending this mail with curl thru my gmail account. Bye! 

Additional info:

  1. I’m using curl version 7.21.6 with SSL support.

  2. You don't need to use the --insecure switch, which prevents curl from performing SSL connection verification. See this online resource for further details.

  3. It’s considered a bad security practice to pass account credentials thru command line arguments. Use --netrc-file. See the documentation.

  4. You must turn on access for less secure apps or the newer App passwords.

like image 131
bambam Avatar answered Sep 20 '22 07:09

bambam


if one wants to send mails as carbon copy or blind carbon copy:

curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \   --mail-from '[email protected]' --mail-rcpt '[email protected]' \   --mail-rcpt '[email protected]' --mail-rcpt '[email protected]' \   --upload-file mail.txt --user '[email protected]:password' --insecure 
From: "User Name" <[email protected]> To: "John Smith" <[email protected]> Cc: "Mary Smith" <[email protected]> Subject: This is a test  a BCC recipient eli is not specified in the data, just in the RCPT list.  
like image 22
soloturn Avatar answered Sep 20 '22 07:09

soloturn