I am trying to send an email using cURL (unfortunately I can't use an API or a php library). I can easily send an HTML format mail -- there are loads of demos and examples of the web. However, I'm struggling to send a simple, plain text email.
I've been trying to adapt the HTML examples, but with no success.
I'm currently sending:
--mail-from john@organisation.com
--mail-rcpt jane@destination.com
--user john.doe:Pa55w0rd
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
From: John Doe <john@organisation.com>
To: Jane Doe <jane@destination.com>
Subject: Test email
Some text
However, the server responds with: 252 2.1.5 Verification not supported
Digging around, I found that this error seems to relate to an attempt to verify the user account (something that is not supported on many mail servers, for understandable security reasons), and not an attempt to send a mail.
My syntax is obviously incorrect, as I am NOT trying to verify a user, but I can't find any examples on the web to work from. But I have successfully sent an HTML mail with embedded images via cURL to the same mail server!
If you use the -T
(--upload-file
) option, curl will not issue a VRFY
command.
See https://ec.haxx.se/usingcurl-smtp.html
Example:
curl smtp://mail.example.com --mail-from myself@example.com \
--mail-rcpt receiver@example.com \
--upload-file email.txt
When curl has a message to send, it will not VRFY and instead do MAIL FROM...RCPT TO
.
From man curl
:
--mail-rcpt (SMTP) Specify a single address, user name or mailing list name.
When performing a mail transfer, the recipient should specify a valid email address to send the mail to. (Added in 7.20.0)
When performing an address verification (VRFY command), the recipient should be specified as the user name or user name and domain (as per Section 3.5 of RFC5321). (Added in 7.34.0)
It's not very well stated, but if the command is lacking a message (-T
or --upload-file
), then curl performs address verification.