Unleashing the Power of `curl`: Sending and Receiving Email via SMTP and POP3
Tue May 5, 2023
Ah, curl
! A tool known far and wide for its web wizardry. But did you know, my friends, that curl
possesses a hidden talent—one that allows you to venture into the realm of email? Prepare yourselves, for today we shall unveil the secrets of using curl
to send and receive email via SMTP.
Sending Email with curl
Let us begin our journey by exploring the art of sending emails with curl
. Behold the command that shall transport your message to its intended recipient:
curl --url 'smtps://smtp.example.com' --ssl-reqd --mail-from 'sender@example.com' --mail-rcpt 'recipient@example.com' --upload-file email.txt --user 'sender@example.com:password'
Now, let us dissect this command to uncover its hidden magic:
--url 'smtps://smtp.example.com'
: Specify the URL of the SMTP server you wish to use for sending the email. In this example, we use an SMTP server hosted atsmtp.example.com
.--ssl-reqd
: Signal that we require a secure SSL/TLS connection for communication with the SMTP server.--mail-from 'sender@example.com'
: Specify the email address of the sender.--mail-rcpt 'recipient@example.com'
: Specify the email address of the recipient.--upload-file email.txt
: Attach the contents of theemail.txt
file as the body of the email.--user 'sender@example.com:password'
: Provide the login credentials for the SMTP server, in the formatusername:password
.
With this command, curl
crafts an email, establishing a connection with the SMTP server and sending it on its way to the recipient.
Receiving Email with curl
Now that we have mastered the art of sending emails, let us explore the intriguing realm of receiving email with curl
. Behold the command that shall retrieve the messages from a POP3 mailbox:
curl --url 'pop3s://pop.example.com' --ssl-reqd --user 'username:password' --output mailbox.txt
Let us unravel the elements of this command:
--url 'pop3s://pop.example.com'
: Specify the URL of the POP3 server hosting the mailbox you wish to access. In this example, we use a POP3 server hosted atpop.example.com
.--ssl-reqd
: Indicate the need for a secure SSL/TLS connection with the POP3 server.--user 'username:password'
: Provide the login credentials for accessing the mailbox, in the formatusername:password
.--output mailbox.txt
: Save the retrieved mailbox contents to a file namedmailbox.txt
.
With this command, curl
establishes a secure connection with the POP3 server, retrieves the contents of the mailbox, and saves them to the designated file.
That’s a wrap
Congratulations, brave adventurers! You have unlocked the hidden powers of curl
in the realm of email. Armed with a few command-line incantations, you can now send and receive emails via SMTP with grace and ease.
Remember, the heart of the curl command lies in the various options and parameters: the SMTP/POP3 server URL, the SSL requirements, email addresses, attachments, and login credentials. Master these, and the world of email shall bow to your will.
Now, my friends, go forth and wield the mighty curl in your email endeavors. Unleash its power to send and receive messages, connecting with the world in a way you never thought possible.
Happy emailing with curl
!