[Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
Hi Python Tutor folks I am stuck with an issue, so am coming to the Pythonistas who rescue me everytime :) I am trying to send out email programmatically, from a gmail a/c, using smtplib, using the following chunk of code (b/w [ ] below) [ import smtplib from email.mime.text import MIMEText #uname, pwd are username password of gmail a/c i am trying to send from server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() # get response(220, '2.0.0 Ready to start TLS') server.login(uname,pwd) # get response(235, '2.7.0 Accepted') toaddrs = ['x...@gmail.com', 'y...@gmail.com' ] # list of To email addresses msg = MIMEText('email body') msg['Subject'] = 'email subject' server.sendmail(fromaddr, toaddrs, msg.as_string()) ] The code above works perfectly fine on my local machine, but fails on the production server at the university where i work( all ports other than port 80 are blocked) :( So , when i try to run the 2 py statements (in bold below) on a python prompt from the production server, which has port 587 blocked, i get the following error { * import smtplib* * server = smtplib.SMTP('smtp.gmail.com:587')* Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python2.6/smtplib.py, line 239, in __init__ (code, msg) = self.connect(host, port) File /usr/lib/python2.6/smtplib.py, line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File /usr/lib/python2.6/smtplib.py, line 273, in _get_socket return socket.create_connection((port, host), timeout) File /usr/lib/python2.6/socket.py, line 514, in create_connection raise error, msg socket.error: [Errno 101] Network is unreachable } 1. How can i overcome this ? A friend suggested , that i could use something called smtp relay, which would solve my problem, but would be time-consuming a pain to set up. I did some cursory googling searching on stackoverflow but could not find any good, well explained results. I dont know anything about SMTP. Anybody has any recommendations on a good explanation on smtp relay how to set it up for sending email from a gmail a/c using a python script ? 2. Also, is there a more elegant/cleaner/graceful solution to my problem than using an smtp relay ? Any all explanations/links/code snippets/thoughts/ideas/suggestions/feedback/comments/ of the Python tutor community would be greatly appreciated. Thanks a ton cheers ashish email : ashish.makani domain:gmail.com ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
On 9/11/2012 2:19 PM ashish makani said... Hi Python Tutor folks I am stuck with an issue, so am coming to the Pythonistas who rescue me everytime :) I am trying to send out email programmatically, from a gmail a/c, using smtplib, using the following chunk of code (b/w [ ] below) [ import smtplib from email.mime.text import MIMEText #uname, pwd are username password of gmail a/c i am trying to send from server = smtplib.SMTP('smtp.gmail.com:587 http://smtp.gmail.com:587/') server.starttls() # get response(220, '2.0.0 Ready to start TLS') server.login(uname,pwd) # get response(235, '2.7.0 Accepted') toaddrs = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com mailto:y...@gmail.com' ] # list of To email addresses msg = MIMEText('email body') msg['Subject'] = 'email subject' server.sendmail(fromaddr, toaddrs, msg.as_string()) ] The code above works perfectly fine on my local machine, but fails on the production server at the university where i work( all ports other than port 80 are blocked) :( Good -- the university is taking steps to block spam. You should send mail using the university mail system and not smtp.gmail.com. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
Folks, some more context so people presume we are spammers :) These emails are automated diagnostic emails sent to a group of a few admins, so we get notified when a python heartbeat script, detects a failure in things like n/w connectivity, router status, etc. We dont use university email, we use gmail. Emile, Please don't presume people's intentions (that we are sending spam) judge people without knowing anything about them. We are a tiny startup trying to connect rural communities using voice ivr systems - http://gramvaani.org/ Best, ashish On Wed, Sep 12, 2012 at 2:56 AM, Emile van Sebille em...@fenx.com wrote: On 9/11/2012 2:19 PM ashish makani said... Hi Python Tutor folks I am stuck with an issue, so am coming to the Pythonistas who rescue me everytime :) I am trying to send out email programmatically, from a gmail a/c, using smtplib, using the following chunk of code (b/w [ ] below) [ import smtplib from email.mime.text import MIMEText #uname, pwd are username password of gmail a/c i am trying to send from server = smtplib.SMTP('smtp.gmail.com:**587 http://smtp.gmail.com:587 http://smtp.gmail.com:587/') server.starttls() # get response(220, '2.0.0 Ready to start TLS') server.login(uname,pwd) # get response(235, '2.7.0 Accepted') toaddrs = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com mailto:y...@gmail.com' ] # list of To email addresses msg = MIMEText('email body') msg['Subject'] = 'email subject' server.sendmail(fromaddr, toaddrs, msg.as_string()) ] The code above works perfectly fine on my local machine, but fails on the production server at the university where i work( all ports other than port 80 are blocked) :( Good -- the university is taking steps to block spam. You should send mail using the university mail system and not smtp.gmail.com. Emile __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
Hi Ashish, On 11 September 2012 22:44, ashish makani ashish.mak...@gmail.com wrote: These emails are automated diagnostic emails sent to a group of a few admins, so we get notified when a python heartbeat script, detects a failure in things like n/w connectivity, router status, etc. We dont use university email, we use gmail. Emile, Please don't presume people's intentions (that we are sending spam) judge people without knowing anything about them. We are a tiny startup trying to connect rural communities using voice ivr systems - http://gramvaani.org/ OK, well I'm sure you can see how an apparent newbie asking to get out of a university network without any explanation can be seem um, suspect, so I think Emile's response was reasonable. I must further note that I can't actually see how/where your request actually fits under the projects listed by that site. So, colour me still a bit sceptical, but I'll give you the benefit of the doubt. So then, given that you can only get out on port 80, your only real option the way I see it is to write a small web service, maybe a SOAP or preferably ReST service, to run on e.g. Google APP engine that will do the emailing for you.Of course, you'll have to consider whether to implement some security yourself if you use port 80 as the data going over the wire will be sent unencrypted. It may not be a problem but then again it may. Note, alternatively you can perhaps also use https (port 443), if that's also open as that will give you end-to-end encryption for free. (But I have no idea and suspect that this may also introduce a boatload of other complications...) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
On Tue, Sep 11, 2012 at 2:44 PM, ashish makani ashish.mak...@gmail.comwrote: Folks, some more context so people presume we are spammers :) These emails are automated diagnostic emails sent to a group of a few admins, so we get notified when a python heartbeat script, detects a failure in things like n/w connectivity, router status, etc. We dont use university email, we use gmail. Emile, Please don't presume people's intentions (that we are sending spam) judge people without knowing anything about them. We are a tiny startup trying to connect rural communities using voice ivr systems - http://gramvaani.org/ I think you might have been presuming Emile's intention too... Blocking port 587 is a standard, prudent, and correct action for the university (ANY network that allows guest access, actually) to take to help prevent spam. The problem is that you (and I do, truly, presume that your intentions are honorable) would not be the only person/system that could use port 587 if it were unblocked. Sure, we trust YOU - but what about everybody else? So there are several ways to go about this: - the standard way, which would be to use the university's SMTP server - which can require a username/password before sending; not perfect but better than nothing - you can work with the university's network admin to grant you or your app an exception to the firewall rule - IF their firewall, and their policies, allow such an exception - you could establish a VPN tunnel to some server outside of the university's network and send from port 587 on THAT machine. Complicated, weird, and not horribly secure. But doable. Best, ashish On Wed, Sep 12, 2012 at 2:56 AM, Emile van Sebille em...@fenx.com wrote: On 9/11/2012 2:19 PM ashish makani said... Hi Python Tutor folks I am stuck with an issue, so am coming to the Pythonistas who rescue me everytime :) I am trying to send out email programmatically, from a gmail a/c, using smtplib, using the following chunk of code (b/w [ ] below) [ import smtplib from email.mime.text import MIMEText #uname, pwd are username password of gmail a/c i am trying to send from server = smtplib.SMTP('smtp.gmail.com:**587 http://smtp.gmail.com:587 http://smtp.gmail.com:587/') server.starttls() # get response(220, '2.0.0 Ready to start TLS') server.login(uname,pwd) # get response(235, '2.7.0 Accepted') toaddrs = ['x...@gmail.com mailto:x...@gmail.com', 'y...@gmail.com mailto:y...@gmail.com' ] # list of To email addresses msg = MIMEText('email body') msg['Subject'] = 'email subject' server.sendmail(fromaddr, toaddrs, msg.as_string()) ] The code above works perfectly fine on my local machine, but fails on the production server at the university where i work( all ports other than port 80 are blocked) :( Good -- the university is taking steps to block spam. You should send mail using the university mail system and not smtp.gmail.com. Emile __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
Walter, Marc, Thanks for your helpful suggestions super quick replies. As a noobie, i often run into brick walls, thinking something(problem i am stuck at) is not possible to do in python. I love struggling against that problem figuring a way out. I have posted to the tutor mailing list in the past the community here has always been amazingly welcoming super helpful, so as a n00b, i was just a little taken aback surprised at Emil's not particularly helpful , yet completely accurate response :) Marc, your 3rd point, you could establish a VPN tunnel to some server outside of the university's network and send from port 587 on THAT machine. Complicated, weird, and not horribly secure. But doable. Could you point me to a good link/resource on how to do this ? Walter, you suggested writing a web service running somewhere else (e.g. Google Apps, AWS, etc) which i could request from my python code, which in turn would do the emailing. Can you point me to any good links/example code which might explain writing a simple SOAP/ReST web service using port80(http) or preferably, 443(https). I know nothing about web services, but could this web service essentially be the python email code, i mentioned in my original post, if i run it on Google App Engine ? Thanks a ton, Best, ashish On Wed, Sep 12, 2012 at 3:29 AM, Walter Prins wpr...@gmail.com wrote: Hi Ashish, On 11 September 2012 22:44, ashish makani ashish.mak...@gmail.com wrote: These emails are automated diagnostic emails sent to a group of a few admins, so we get notified when a python heartbeat script, detects a failure in things like n/w connectivity, router status, etc. We dont use university email, we use gmail. Emile, Please don't presume people's intentions (that we are sending spam) judge people without knowing anything about them. We are a tiny startup trying to connect rural communities using voice ivr systems - http://gramvaani.org/ OK, well I'm sure you can see how an apparent newbie asking to get out of a university network without any explanation can be seem um, suspect, so I think Emile's response was reasonable. I must further note that I can't actually see how/where your request actually fits under the projects listed by that site. So, colour me still a bit sceptical, but I'll give you the benefit of the doubt. So then, given that you can only get out on port 80, your only real option the way I see it is to write a small web service, maybe a SOAP or preferably ReST service, to run on e.g. Google APP engine that will do the emailing for you.Of course, you'll have to consider whether to implement some security yourself if you use port 80 as the data going over the wire will be sent unencrypted. It may not be a problem but then again it may. Note, alternatively you can perhaps also use https (port 443), if that's also open as that will give you end-to-end encryption for free. (But I have no idea and suspect that this may also introduce a boatload of other complications...) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
On 9/11/2012 2:44 PM ashish makani said... Emile, Please don't presume people's intentions (that we are sending spam) judge people without knowing anything about them. I made no such presumption -- I appluad the university for taking appropriate actions to reduce the spread of spam. Perhaps you're not familiar with spam botnets. See http://en.wikipedia.org/wiki/Botnet Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
On Tue, Sep 11, 2012 at 3:27 PM, ashish makani ashish.mak...@gmail.comwrote: Marc, your 3rd point, you could establish a VPN tunnel to some server outside of the university's network and send from port 587 on THAT machine. Complicated, weird, and not horribly secure. But doable. Could you point me to a good link/resource on how to do this ? Hmmm... having said that, I'm puzzling over the simplest way to actually do it. First idea (based on stuff I've set up in the past): - at your outside location, set up a VPN endpoint/router, with your SMTP server sitting behind it - on your computer inside the university's network, install a VPN client and establish the tunnel before launching your script I am very fond of pfSense http://www.pfsense.org as a router/firewall; it has OpenVPN http://openvpn.net/index.php/open-source.html support baked in, and if you install the OpenVPN Client Export Utility package (a single click, once pfSense is installed) it will export a ready-made configuration file for the remote machine. Two things: - as I said, this is a complicated and weird way to do this, although it's probably more secure than I thought when I first mentioned it. But it's probably NOT the best way to go about it. - somebody out there, with better Python chops than I, will no doubt point out a way to do the same thing all in Python. Even if this were the proper approach, I'm not guaranteeing it's the best way to implement it. If you do decide to go this way, you'll need a machine (it could even be a virtual machine, but I find it much simpler to use an old junker PC with two network cards) to run pfSense, and of course an SMTP server. I'd just like to add a quick endorsement for pfSense in general, by the way - it's free and open-source, but I have yet to find anything it doesn't do, and do well, compared to Cisco/Juniper/SonicWall/etc. Of course, the old junker PC you run it on needs to be in decent working condition - stable power supply (and power!), no flaky memory or unstable NICs - but it doesn't need to be very new or very powerful. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to send email from a gmail a/c using smtp when port 587(smtp) is blocked
Why don't you ask the university to setup a password protection on port 587 to allow access to specific users, and then they can monitor the incoming/outgoing connections identified by the user name? As well as encryption known by the university to monitor activity on other levels. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor