Hello Guest it is April 23, 2024, 11:32:24 PM

Author Topic: Send Email  (Read 3266 times)

0 Members and 1 Guest are viewing this topic.

Send Email
« on: January 23, 2017, 11:29:43 PM »
I'm wanting to send an email once my machine is finished running.  I'm referencing this thread where Steve posted an example.

http://www.machsupport.com/forum/index.php/topic,32001.msg222766.html#msg222766

I get to this line "local smtp = require("/socket.smtp")" and it pops up a window to open up another file.  

Also, anyone know the gmail server I need to use.  Where I've read online, Gmail doesn't use port 25.

The following link says the port needs to be 587 for ssl
https://www.lifewire.com/what-are-the-gmail-smtp-settings-1170854


Any ideas on how to get this to work?
« Last Edit: January 23, 2017, 11:33:17 PM by Cbyrdtopper »
Chad Byrd

Offline smurph

*
  • *
  •  1,546 1,546
  • "That there... that's an RV."
    • View Profile
Re: Send Email
« Reply #1 on: January 24, 2017, 04:45:03 AM »
It is asking you to find the required module.  Simply pick smtp.lua.  When the require keyword is used in a LUA script, think of it as "including" that script.  Also think of:

local smtp = require("/socket.smtp")

as short hand for:

local smtp = require(cpath .. "/socket/smtp.lua")

For port 587, that will require SSL.  I think there was a post on here somewhere that deals with using SSL along with the sokets smtp module.  Search around for it.  I worked with Chaoticone on getting that working at some point, but I do not remember the details. 

Steve

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Send Email
« Reply #2 on: January 24, 2017, 08:24:54 AM »
This is a tested sample. Obviously the email addresses, host names, ports, passwords, etc. will need to be replaced with the actual ones you plan to use. There are two parts to this example. The button script will go in a buttons clicked script. All it does is run the email function passing it a message (must be a string) as a parameter. The email function goes in the screen load script.

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

--Screen Load Script
---------------------------------------------------------------
-- 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))
    end
end
;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!
Re: Send Email
« Reply #3 on: January 24, 2017, 08:48:26 AM »
When I run the debugger and step through the macro, it continually asks me to select the smpt.lua file.  I guess this means I can't step through the macro. 

I decided to just run the macro instead, this seems to do better, it runs through and doesn't give me any erros on Steve's example, but it didn't send an email.   

When I run Chaoticone's example, I get a message box that says "authentication not supported."
Chad Byrd

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Send Email
« Reply #4 on: January 24, 2017, 10:15:34 AM »
Hmmmmmmm, that error is being generated in the email function. I wont be able to help much with that. I have tested it again this morning and its working fine for me. About the only suggestion I have is to make sure your password and user name is correct in the function. If that is not the problem hopefully Steve or others will reply.
;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!
Re: Send Email
« Reply #5 on: January 24, 2017, 10:47:18 AM »
I was running Steve's example in the editor this morning, I modified this line **"local smtp = require('/socket.smtp')"** to this **local smtp = require(cpath .. "/Modules/socket/smpt.lua")**  and it didn't keep asking me for the SMPT file.  It gave me an error, but the error was this: 

Got a socket error trying to read. Address '10.1.10.31'. Port 60769.
Got a socket error trying to read. Address '10.1.10.31'. Port 60769.

That address (10.1.10.31.) is my computer's address, it is what we have set at our shop so we can have a network for specialized programs across our admin computers in the shop.  I realize it is more network related than Mach, but could this be a potential problem that is carrying over to your example, Chaoticone?
Chad Byrd
Re: Send Email
« Reply #6 on: January 24, 2017, 12:00:26 PM »
I gave my smtp.send {  a port of '465' and instead of getting a message box saying "authentication not supported" it thinks for about 5 seconds and then gives me a message box that said "closed".  Any ideas why that would have changed?
Chad Byrd