Over three days I have read hundreds of posts on using curl
to send basic smtp email. I started with using mail
, which ends up using exim4
on my system (Debian Linux), but it didn’t work and I get almost no information using -d or -v options, so gave that up.
Curl tells me it is able to connect to the server, establish a TLS connection, and successfully authenticate. Then it tells me the URL is no good, which seems to be its answer to every problem and doesn’t make sense. And of course I don’t get the email. I’ve tried countless variations on quotes etc. Here is my best curl attempt and the output (email addresses and password redacted):
#!/usr/bin/zsh
SMTP='mail.forestpathology.org'
PORT=465 # SSL/TLS is port 465; non-SSL is 2525
USER='[email protected]'
PASS='-------'
SERVER='Tabernacle'
FROM='[email protected]'
TO='[email protected]'
cat mail.txt
curl -v --ssl-reqd
--url smtps://$SMTP:$PORT
--user $USER:$PASS
--mail-from $FROM
--mail-rcpt $TO
--upload-file mail.txt
Tabernacle:~$ sudo bin/testsm.zsh
From: "User Name" <[email protected]>
To: "John Smith" <[email protected]>
Subject: This is a test
Hi John,
I’m sending this mail with curl thru my gmail account.
Bye!
* Trying 70.32.23.63:465...
* Connected to mail.forestpathology.org (70.32.23.63) port 465 (#0)
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
* subject: CN=forestpathology.org
* start date: May 26 20:05:10 2024 GMT
* expire date: Aug 24 20:05:09 2024 GMT
* subjectAltName: host "mail.forestpathology.org" matched cert's "mail.forestpathology.org"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
< 220-mi3-ss52.a2hosting.com ESMTP Exim 4.96.2 #2 Tue, 28 May 2024 16:47:53 -0400
< 220-We do not authorize the use of this system to transport unsolicited,
< 220 and/or bulk e-mail.
> EHLO Tabernacle
< 250-mi3-ss52.a2hosting.com Hello Tabernacle [97.120.128.182]
< 250-SIZE 78643200
< 250-8BITMIME
< 250-PIPELINING
< 250-PIPECONNECT
< 250-AUTH PLAIN LOGIN
< 250 HELP
> AUTH PLAIN
< 334
> AGp3b3JyYWxsQGZvcmVzdHBhdGhvbG9neS5vcmcAZGlhbHlzaXMtYW50aGVyLXNjYWJpZXM=
< 235 Authentication succeeded
> HELP
< 214-Commands supported:
214-Commands supported:
< 214 AUTH HELO EHLO MAIL RCPT DATA BDAT NOOP QUIT RSET HELP
214 AUTH HELO EHLO MAIL RCPT DATA BDAT NOOP QUIT RSET HELP
* Connection #0 to host mail.forestpathology.org left intact
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
Tabernacle:~$