What are the Curl SMTP command line arguments to support GMail TLS/STARTTLS vs SSL - email

I am using Curl.exe in an application to send emails. I need to support most major email servers. GMail exposes the following ports and Authentication methods.
TLS/STARTTLS (sometimes called Explicit TLS): uses port 587
SSL (sometimes called Implicit TLS): uses port 465
I have gotten the Explicit TLS to work using the following command line:
C:\>curl smtp://smtp.gmail.com:587 -v --mail-from "my.mail#gmail.com" --mail-rcpt
"your.mail#x.com" --ssl -u my.mail#gmail.com:password -T "c:\test.txt" -k --anyauth
I have tried the following to get ImplicitTLS to work, but it is not.
C:\>curl smtp://smtp.gmail.com:465 -v --mail-from "my.mail#gmail.com" --mail-rcpt
"your.mail#x.com" --ssl -u my.mail#gmail.com:password -T "c:\test.txt" -k --anyauth
What are the proper command line parameters to get SSL/Implicit TLS to work?

Use smtps:// for SMTPS (i.e. SMTP on top of an existing SSL/TLS connection).
This works:
curl smtps://smtp.gmail.com:465 -v
I would also use --ssl-reqd for the explicit STARTTLS connection to make sure SSL/TLS is used when you expect it to be (downgrade attacks would be possible otherwise).
Don't use -k either, check the server certificate: see http://curl.haxx.se/docs/sslcerts.html

well i just tried the following and it works fine:
curl smtps://smtp.gmail.com:465 -v --mail-from "xxx#gmail.com" --mail-rcpt "yyy#gmail.com" --ssl -u xxx#gmail.com:password -T "test.txt" -k --anyauth
hope it helps!

Your can try this..
curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender#gmail.com" --mail-rcpt "recepient#gmail.com" --upload-file /var/scripts/mail.txt --user "sender#gmail.com:senderGmailPassword"

You can test using this command:
curl -v --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender#gmail.com" --user "sender#gmail.com" --mail-rcpt "sender#gmail.com"
You will have to create a new 16 digits password specific for this application and simply change the account password to this new secure app password. Now you can create one password for each app. It will keep your account password safe and manage app passwords separately.
Login to your account to create it:
https://myaccount.google.com/apppasswords
You must enable the 2-Step Verification (https://myaccount.google.com/signinoptions/two-step-verification) to access this feature.
To help keep your account secure, from May 30, 2022, ​​Google no
longer supports the use of third-party apps or devices which ask you
to sign in to your Google Account using only your username and
password.
https://support.google.com/accounts/answer/6010255

Related

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:
or PowerShell as follows:
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:
where the mail.txt file is:
So, what is wrong with my curl command? Thanks.
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

How to assemble preemptive auth in curl command , while using POST method

I need to use POST method for a REST API.It's working perfectly in SOAP UI while i select "Preemptive Authentication" , I need to assemble this authentication option in Curl.
At Web service , preemptive properties has not set. It has only Basic authentication system with username & password.
I have tried --anyauth , it's not working. I have below command.
curl -X POST -H "content-type:application/json" --verbose -u username:password http://example.net:1234/api/Flows/UpdateStatus -d '{"EventId": "123","Status": "success"}'
I am always getting below error.
{"Message":"Authorization has been denied for this request."}
I had tried with providing base64 encoded value of user & password at header section instead of providing user & password under user section ,and it got worked for me.
curl -X POST -H "content-type:application/json" --verbose -H "Authorization: Basic Base64_encoded_value_of_user_&_password" http://example.net:1234/api/Flows/UpdateStatus -d '{"EventId": "123","Status": "success"}'

IBM watson internet of things platform: Connecting using client certs & mosquitto client

I get below error while trying to connect to IBM Watson internet of things platform using client certs & mosquitto client. The same certs work fine with node.js client hence I know certs are fine, just some config in mosquitto client which is erroneous.
mosquitto_sub -h dumorg.messaging.internetofthings.ibmcloud.com -p 8883 --capath ./certs/ -t "iot-2/type/dumtype/id/dumid/cmd/+/fmt/json" -v -i g:dumorg:dumtype:dummid --cert ./client.crt --key ./client.key
Connection Refused: not authorised.
When I try to perform same connection using auth-token it goes through fine
$ mosquitto_sub -h dumorg.messaging.internetofthings.ibmcloud.com -p 8883 --capath ./certs/ -t "iot-2/type/dumtype/id/dumid/cmd/+/fmt/json" -v -i g:dumorg:dumtype:dumid -P dumpassword -u use-token-auth
I am also able to successfully connect using certs through another client. I know the certs are fine, and mosquitto command works with auth token. hence issue is some missing/incorrect config in mosquitto due to which IoT platform doesn't like certs used to connect with mosquitto?
Seems mosquitto does not support SNI which is required to connect to MQTT broker on IBM cloud. Manually inserting this patch https://github.com/eclipse/mosquitto/pull/626 and building mosquitto resolved issue. Hope this is merged in main branch in near future.

Bluemix Connection Refused: not authorised, can't register device

I have read several tutorials and topics and I did everything as described, but still I am not able to register device.
I have been trying to use MQTTlens and mosquitto but same problem, not authorised
Bellow is command for mosquitto
mosquitto_pub -h xwc8vm.messaging.internetofthings.ibmcloud.com -u use-token-auth -P 'YpSP?P98Wwe0pYGXPj' -i 'd:xwc8vm:devicetype:mydevice' -t /iot/x -m '{"d":"heloo"}'
This are devices data
Organization ID xwc8vm
Device Type devicetype
Device ID mydevice
Authentication Method token
Authentication Token XXXXXXXXXX
I have used host
xwc8vm.messaging.internetofthings.ibmcloud.com
and client
d:xwc8vm:devicetype:mydevice
I even tried using http://mqtt-helper.mybluemix.net/?cm_sp=dw-bluemix--nospace--answers, but got this error
(23:42:45.044)Failed to connect to xwc8vm.messaging.internetofthings.ibmcloud.com:1883. Code: 1, Message: AMQJSC0001E Connect timed out.
Everything is configured as here http://heidloff.net/article/useful-mqtt-tools-ibm-watson-iot-bluemix?cm_mc_uid=27677244132415055778021&cm_mc_sid_50200000=1505944109
You can check your TLS security setting in your dashboard under the security tab. New IoT services by default require TLS. If you are not using TLS then try setting it to optional to see if that resolves the problem.
The mosquito command is not complete, you need to specify the port 8883, and the connection is secure by default and you need to specify the server certificate that can be downloaded from below:
https://github.com/ibm-watson-iot/iot-python/blob/master/src/ibmiotf/messaging.pem
So the command should look like:
mosquitto_pub -h xwc8vm.messaging.internetofthings.ibmcloud.com -p 8883 -u "use-token-auth" -P "xxxxxxxxx" -i "d:xwc8vm:device-type:my-device" -t "iot-2/evt/x/fmt/json" -m {"d":"hello"} --cafile messaging.pem -d
messaging.pem file needs to be in the same location as mosquitto_pub file or you can pass the path to it
Note: Please mind the topic format:
"iot-2/evt/x/fmt/json" >>>>> iot-2/evt/event/fmt/event_format
Very important, please edit your post and remove or mask the authentication token

Bluemix - Natural Language Classifier credentials in the Questions on classifier demo

I'm trying to use IBM Watson Natural language Classifier but I can't proceed and load my answers. For some reason, username and password aren't working all the time.
This one executed fine:
curl -u username:password -F training_data=#questions.csv -F
training_metadata="{\"language\":\"en\",\"name\":\"my_classifier\"}"
"https://url/v1/classifiers"
But when I try to execute the following command, it doesn't work:
curl -u username:password -X POST -H "Content-Type: application/json"
-d #questions-with-classifier-ega-war/target/classes/answers.json http://yourAppName.mybluemix.net/api/v1/manage/answer
It just asks for the user and password again and again. It is the same password that just worked in the first curl command.
Thanks in advance!
I think you are confusing the service credentials (the one you use in the first command) with the credentials used to manage the database in one of the sample applications "Questions on Classifier" (see pom.xml).
In order to run your second command make sure you use the credentials from the pom.xml in your root directory