Search code examples
powershellemailcurlexchange-servertelnet

Sending mail with curl on Windows via MS Exchange Server


I am trying to send an email using curl on Windows 10 through an MS Exchange Server. The email is sent to another user in the same Active Directory domain, and the user who is sending the email is already authenticated under Windows.

Given the above, I can successfully send an email using telnet as follows:

enter image description here

enter image description here

or PowerShell as follows:

enter image description here

Given that the above two commands work, I am looking for the equivalent curl command. I have looked at the following SO answer:

Using curl to send email

and tried the following command (and many other combinations of options), but with no success.

curl -v --url "webmail.jXs.com:25" --mail-from "r@jXs.com" --mail-rcpt "s@jXs.com" --upload-file mail.txt

I get the following output:

enter image description here

where the mail.txt file is:

enter image description here

So, what is wrong with my curl command? Thanks.


Solution

  • Apparently when using curl, we have to specify the smtp communication protocol in the url (which is not necessary when using telnet or powershell). So, adding smtp:// to the url made the curl command work.

    curl -v --url "smtp://webmail.jXs.com:25" --mail-from "r@jXs.com" --mail-rcpt "s@jXs.com" --upload-file mail.txt