Curl is commonly known as its capability dealing with HTTP and HTTPS services. But in fact it has a wide range of protocol that are supported. This make it a perfect tool for testing in some of the restricted environment where other tool could not be easily obtained. The same applies to the container environment.
Let’s explore some of theses protocols curl supports.
Telnet with Curl
Open a telnet session with curl using the common format as
For an example, the HTTP service, type in “GET / HTTP/1.0” and enter twice, then we will have the HTTP response.
GET / HTTP/1.0
HTTP/1.0 200 OK
Date: Thu, 13 Apr 2023 08:12:59 GMT
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-0UjfoqjKKH08-IJyvrc2KA' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
With the telnet, we can send email to a SMTP server on the telnet session. But a better approach is to use the built-in protocol support for SMTP.
Send SMTP Email with Curl
Let’s prepare a email text file, named as email.txt, as below,
Subject: Test email
This is just a test emappil.
Now using the following curl command talk to the SMTP server to send the email.
curl -v smtp://sandbox.smtp.mailtrap.io \
--mail-from email@example.com \
--mail-rcpt firstname.lastname@example.org \
--upload-file email.txt --user username:password
Some of the verbose output is listed as below,
< 220 smtp.mailtrap.io ESMTP ready
> EHLO email.txt
> MAIL FROM:<email@example.com> SIZE=114
< 250 2.1.0 Ok
> RCPT TO:<firstname.lastname@example.org>
< 250 2.1.0 Ok
< 354 Go ahead
} [114 bytes data]
* We are completely uploaded and fine
< 250 2.0.0…