14
votes

I am using Curl.exe in an application to send emails. I need to support most major email servers. GMail exposes the following ports and Authentication methods.

  • TLS/STARTTLS (sometimes called Explicit TLS): uses port 587
  • SSL (sometimes called Implicit TLS): uses port 465

I have gotten the Explicit TLS to work using the following command line:

C:\>curl smtp://smtp.gmail.com:587 -v --mail-from "[email protected]" --mail-rcpt 
"[email protected]" --ssl -u [email protected]:password -T "c:\test.txt" -k --anyauth

I have tried the following to get ImplicitTLS to work, but it is not.

C:\>curl smtp://smtp.gmail.com:465 -v --mail-from "[email protected]" --mail-rcpt 
"[email protected]" --ssl -u [email protected]:password -T "c:\test.txt" -k --anyauth

What are the proper command line parameters to get SSL/Implicit TLS to work?

3
You've swapped explicit/implicit: when you say START SSL/TLS, you tell it explicitly to start. Note that both can use SSL or TLS in general. (I wrote a long answer on SF about this.)Bruno
Thanks for the heads up. I swapped the explicit and implicit descriptions.Kevin Westwood
Have you tried to use smtps://...?Bruno

3 Answers

16
votes

Use smtps:// for SMTPS (i.e. SMTP on top of an existing SSL/TLS connection).

This works:

curl smtps://smtp.gmail.com:465 -v

I would also use --ssl-reqd for the explicit STARTTLS connection to make sure SSL/TLS is used when you expect it to be (downgrade attacks would be possible otherwise).

Don't use -k either, check the server certificate: see http://curl.haxx.se/docs/sslcerts.html

12
votes

well i just tried the following and it works fine:

curl smtps://smtp.gmail.com:465 -v --mail-from "[email protected]" --mail-rcpt "[email protected]" --ssl -u [email protected]:password -T "test.txt" -k --anyauth

hope it helps!

2
votes

Your can try this..

curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "[email protected]" --mail-rcpt "[email protected]" --upload-file /var/scripts/mail.txt --user "[email protected]:senderGmailPassword"