Jump to content

Recommended Posts

Posted

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?

Posted

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

Posted

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 python
import cgi
import smtplib
argv=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);
Posted

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
Posted (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 by xittle
Posted (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 by xittle
Posted

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.

Posted

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;
Posted
# /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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...