r/javahelp • u/goodnewsjimdotcom • Oct 11 '19
How do I send a SMS? Aka instant message.
I am doing an e-commerce site, and I want to add a layer of security to tie accounts to two factor verification. What is the simplest or best way to send a sms via java?
3
u/irocgts Oct 11 '19 edited Oct 11 '19
So there is a way without third party software but its weird. You can send emails to phone numbers if you know the right address. Each carrier is different. This is the link for verizon, just read 'How do I send a text to a mobile number from my email?' part: https://www.verizonwireless.com/support/text-messaging-faqs/
edit: I didn't read the whole question. I guess this is more of a fun fact. Don't do this if you are making a commercial product. This is more of like a college project fun thing. You really should use a 3rd party API.
2
u/irocgts Oct 11 '19
This was sort of common knowledge a bunch of years ago (~20 years) before these 3rd parts APIs were well known. I am glad its still a thing.
2
u/wildjokers Oct 11 '19
Need to use an API or have a relationship with all the carriers.
https://rapidapi.com/collection/free-sms-apis
Those apis are either free or offer a free trial or offer a certain number of messages for free then start charging.
Twilio is crazy cheap though, something like 0.007 cents per SMS to a US number. You get $15 dollars free with your trial account. Have to pay $1 of that for a number leaving you $14 to send SMS messages. That is about 2000 SMS messages.
I am still using the free trial account to get text notifications when my 3d prints are done (should last me a few years).
1
15
u/mjg123 Oct 11 '19 edited Oct 11 '19
You can send SMS using a service like Twilio: https://www.twilio.com/docs/sms/quickstart/java.
Once you have an account you can send an SMS in 2 lines of code. There's also higher-level 2FA-specific services if you need them.
(NB I work for Twilio - any questions, hit us up in /r/twilio)