How to send email with curl command line using the iCloud SMTP server?

Viewed 36

I have to send an email from within my macOS application using NSTask and curl. The email contains just a small text-log of a daily task, that the user could daily send to himself.

The curl command line here below works well for any of my SMTP servers but it doesn't work with the SMTP from my iCloud account smtp.mail.me.com nor with my gmail.com one.

Since I don't know the SMTP that the final user will define and use, I would code a curl command line that works with any SMTP, included the one from iCloud smtp.mail.me.com or from gmail.com. But I can't achieve my goal.

When I try this code from the Terminal

curl --ssl --tlsv1.3 -H 'Authorization:AUTH LOGIN base64User:password' --url 'smtp://smtp.mail.me.com:587' --mail-from user@mac.com --mail-rcpt user@mac.com --upload-file /Users/me/Desktop/header_mail.txt -v

I get the following log with the error Client host rejected: Access denied.

…
*  SSL certificate verify ok.
> EHLO header_mail.txt
< 250-123456789.me.com
< 250-PIPELINING
< 250-SIZE 28311552
< 250-ETRN
< 250-AUTH LOGIN PLAIN ATOKEN WSTOKEN WETOKEN
< 250-ENHANCEDSTATUSCODES
< 250-8BITMIME
< 250-DSN
< 250 CHUNKING
> MAIL FROM:<user@mac.com> SIZE=311
< 250 2.1.0 Ok
> RCPT TO:<user@mac.com>
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0< 554 5.7.1 <unknown[MY_PUBLIC_IPv4_ADDRESS]>: Client host rejected: Access denied
* RCPT failed: 554
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
> QUIT
< 221 2.0.0 Bye
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, close notify (256):
} [2 bytes data]
curl: (55) RCPT failed: 554

I have been searching for the error from curl Client host rejected: Access denied and I found many answers, but nothing regarding the 'smtp.mail.me.com' case.

Can I really send an email using using a curl command line from my iCloud account SMTP or is it forbidden? If allowed, what do I miss in the curl command line here above? Thanks.

0 Answers
Related