Hello Guest it is October 22, 2019, 10:36:27 AM

Author Topic: sms to phone  (Read 983 times)

0 Members and 1 Guest are viewing this topic.

sms to phone
« on: October 31, 2017, 11:56:17 AM »
I would like to be notified when a script is complete by sending a SMS text message to my cell phone.
Has anyone successfully been able to do this with Mach4?  I found this snippet from the web but I get an error message:
Got a socket error trying to read. Address ''. Port 52181

-- load the smtp support
local sckt = require("socket.smtp")

-- Connects to server "localhost" and sends a message to users
from = "<luasocket@example.com>"

rcpt = {

mesgt = {
  headers = {
    to = "Ralph Tuttle <myPhoneNumberHere@vtext.com>",
    subject = "CNC Lathe Task Complete"
  body = "CNC Lathe Task Complete, body"

r, e = sckt.send{
  from = from,
  rcpt = rcpt,
  source = smtp.message(mesgt)



Re: sms to phone
« Reply #1 on: January 05, 2018, 06:26:54 PM »
Has anyone successfully got the C:\Mach4Hobby\Modules\ smtp-Example.lua to work?
Re: sms to phone
« Reply #2 on: January 11, 2018, 06:13:52 PM »
We use a pay service called Nexmo.  I believe it is a just a few cents per text but it may have gone up.  If you install a program called cURL, you can access a url through the command line. Nexmo will give you a url to load that will automatically send a text to the number you give them and then you can create a .bat file that looks like this:

cd\your directory
cmd /k curl "https://rest.nexmo.com/sms/json?api_key=**********&api_secret=***********&from=1208675309&to=17208675309&text=hello+world"

We have this running on Mach3 currently, but it should work with lua if you use os.execute like this:

os.execute("C:\\your directory\\yourtextmessagefile.bat")

This works nicely for sending a text once a job is finished. We only have it execute a windows command line after any moving parts have fully stopped.  I don't know how robust Mach4 is, but I don't feel like running a windows command while it is still moving is good practice.

There are definitely ways to do this for free, (probably just sending an email using a .bat file to vtext would work fine) but we pay so little for Nexmo that I haven't gotten around to changing it.

Hope this gives you some ideas!

Re: sms to phone
« Reply #3 on: January 11, 2018, 11:05:45 PM »
I decided to go ahead and update things to a email-to-sms type system.  Instead of myPhoneNumberHere@vtext.com we use google fi's myPhoneNumberHere@msg.fi.google.com. It's the same thing, and you can get a list of all of the carrier's appropriate email to sms addresses online.

I installed a program called sendEmail from http://caspian.dotconf.net/menu/Software/SendEmail/
This allows you to send an email from the windows command prompt. There are a lot of ways to do this, but this one is very easy.

Here is an example command for the sendEmail program:
c:\your directory\sendEmail.exe -f Sender'sAddress@gmail.com -t YourPhoneNumberHere@msg.fi.google.com -s smtp.gmail.com:587 -xu YourUsername@gmail.com -xp YourPassword -u "test" -m "hello world"

After filling in your individual information, save the command as a .bat file, and then in Lua use:
os.execute("C:\\your directory\\yourtextmessagefile.bat")

This is simpler, freer, and you can also use a regular email address if you don't want it to go to sms. If someone knows how to get it working without using the windows command prompt, then I'm sure that would be a much more elegant solution, but this works great for what I need.

« Last Edit: January 11, 2018, 11:08:02 PM by dbt3000files »
Re: sms to phone
« Reply #4 on: January 12, 2018, 02:43:10 PM »
thanks dbt3000files,

I use t-mobile so instead of the @msg.fi.google.com I use @tmomail.net, each carrier has a gateway.  

I put the following in a button left up script to test whether a batch file is needed, you don't, and it works.  I think making a function in the load script that takes a string and appends that as the message (-m) would make it more useful.  You could call it with a more specific message.
os.execute('c:\\Mach4Hobby\\sendEmail.exe -f myemail@mail.com -t 1111111111@tmomail.net -s smtp.mail.com:587 -xu myemail@mail.com -xp mypassword -u "test" -m "hello world"')

Thanks for providing the links.


Online Chaoticone

  • *
  •  5,610 5,610
  • Precision Chaos
    • View Profile
Re: sms to phone
« Reply #5 on: January 12, 2018, 07:28:05 PM »
I tested sending an email one time and had it all working good. I don't remember much about it but did save a script. Here it is.

Code: [Select]
--Button Script
email('Hello from a Mach4 machine') --This calls the email function and passes it a message.

-- Email added 8-30-2016
--Helpful link http://w3.impa.br/~diego/software/luasocket/smtp.html
function email(message)
    package.path = package.path .. ';./Modules/?.lua;'
    package.cpath = package.cpath .. ';./Modules/?.dll;'

    -- load the smtp support
    local smtp = require('/socket.smtp')
from = '<fromname@hostname.net>' --email address of sender

    rcpt = {
        '<toname1@hostname.net>', --email address of recipient
'<toname2@hostname.net>', --email address of carbon copied recipient
'<toname3@hostname.net>' --email address of blind carbon copied recipient. They will be blind because we will not list them in the header

    mesgt = {
        headers = {
            from = 'From Name <fromname@hostname.net>', --name and email address of sender. Example: 'John Doe <originaljdoe@anyhost.net>'
            to = 'To Name <toname1@hostname.net>', --name and email address of recipient
cc = 'To Name <toname2@hostname.net>', --name and email address of someone being carbon copied
subject = 'Mail from a Mach4 machine' --email subject
        body = tostring(message)

    r, e = smtp.send{
        from = from,
        rcpt = rcpt,
        source = smtp.message(mesgt),
        server = 'mail.myhost.net', --this is the address or IP of the mail server used to send this email. smtp.gmail.com is one example
        password = 'MailServerPassword', --this is the password you use to access the mail server you are sending from
        user = 'myname@myhost.net' --this is the user name you use to access the mail server you are sending from
    if (r == 1) then --Message was sent successfully
       wx.wxMessageBox('Message was sent successfully.')
    else --There was an error
        wx.wxMessageBox('!!!ERROR!!!\n\n' .. tostring(e))
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!