xittle Posted November 7, 2017 Posted November 7, 2017 I've been setting up a notification system for users on a service I have set up on heliohost, but have encountered a major issue. I am sending mail via a python script (mail.py), which takes several arguments and sends the mail, but my php cannot use shell_execute or system to run this script. What is a method that is allowed on heliohost?
Bailey Posted November 7, 2017 Posted November 7, 2017 A JavaScript/HTML submit button that links to the script works for me.
Krydos Posted November 7, 2017 Posted November 7, 2017 Put mail.py in cgi-bin or make python scripts executable in public_html with .htaccess, and then pass the arguments to it like domain.heliohost.org/cgi-bin/mail.py?address=example@domain.com&arg1=hello&arg2=goodbye
xittle Posted November 8, 2017 Author Posted November 8, 2017 Update: I tried krydos's solution but I'm getting a 500 internal server error.Help? Here is the python file (in cgi-bin):#!/usr/bin/env pythonimport cgiimport smtplibargv=cgi.FieldStorage();s=smtplib.SMTP("mail.smtp2go.com", 2525);s.login((my username),(my password));s.sendmail(argv["sen"],sys.argv["rec"],sys.argv["mess"]);print("Content-type: text/html")print();print(argv);
Krydos Posted November 8, 2017 Posted November 8, 2017 You've got a syntax error.root@johnny [/home/xittle/public_html/cgi-bin]# /usr/bin/python mail.cgi File "mail.cgi", line 6 s.login((my username),(my password)); ^ SyntaxError: invalid syntax #!/usr/bin/env python Also, I want to point out that if you use this shebang you're using a truly ancient version of python 2.6.6 which was released in 2010. I recommend you use /usr/bin/python2.7 or /usr/bin/python3.6
xittle Posted November 8, 2017 Author Posted November 8, 2017 (edited) I am still having this problem even with appropriate syntax changes. I even commented out smtplib elements so that it just prints a list of argument values. Edited November 8, 2017 by xittle
Krydos Posted November 8, 2017 Posted November 8, 2017 I recommend you use /usr/bin/python2.7 or /usr/bin/python3.6#!/usr/bin/python27 Do you see the difference?
xittle Posted November 8, 2017 Author Posted November 8, 2017 (edited) I changed it to that after 2.7 didn't work, knowing on some machines the actual executable is named python27. It was a tweak that didn't work. I just changed it back, and it doesn't work as before.Partially Solved: I had tried 2.7 and 27 but didn't touch 3.6, which worked in the end. However, now the smtp part won't work. Edited November 8, 2017 by xittle
Krydos Posted November 8, 2017 Posted November 8, 2017 We're working through it one issue at a time. I usually stop looking for problems as soon as I find one. The next issue I see is you're using the wrong type of line endings. The easiest way to fix this is to create the file through cpanel file manager. Then click the code editor and copy/paste your code in. The default encoding and line endings that cpanel file manager uses is compatible with cgi. The other option is you can use a linux capable editor like notepad++ instead.
xittle Posted November 8, 2017 Author Posted November 8, 2017 Fixed line endings, however I still have the smtp problem.I added some comments to my code to show where the problem is happening, #!/usr/bin/python3.6 import cgi import smtplib argv=cgi.FieldStorage(); #all commented lines other than this one are commented because they would return an error 500 #this line will not work s=smtplib.SMTP("mail.smtp2go.com", 2525); #this line depends on 5 s.login("BitDragon_Server",My_private_password"); #this line depends on 5 s.sendmail(argv["sen"].value,argv["rec"].value,argv["mess"].value); print("Content-type: text/html") print(); for element in argv.keys(): print(argv[element].value;
Krydos Posted November 8, 2017 Posted November 8, 2017 # /usr/bin/python3.6 Python 3.6.1 (default, Jul 1 2017, 22:46:39) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import smtplib >>> s=smtplib.SMTP("mail.smtp2go.com", 2525); Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python3.6/lib/python3.6/smtplib.py", line 251, in __init__ (code, msg) = self.connect(host, port) File "/usr/local/python3.6/lib/python3.6/smtplib.py", line 335, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/local/python3.6/lib/python3.6/smtplib.py", line 306, in _get_socket self.source_address) File "/usr/local/python3.6/lib/python3.6/socket.py", line 722, in create_connection raise err File "/usr/local/python3.6/lib/python3.6/socket.py", line 713, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused That would be because port 2525 is closed. Is there any particular reason it's on such a strange port? Does 25, 465, or 587 work for this service. Those are standard smtp ports.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now