On this site, someone said that to send a message over smtp gmail, you didnt need tls. im working with a port of python with basically supports everything but https, ssl, tls so libgmail, etc doesnt work. i have found a way to get my mail without those things(via gmail atom feeds) but i need a way to send messages.
this is the code that i am working with (gmailer):
if i comment out the underlined parts, it doesnt not work. any hints?
this is the code that i am working with (gmailer):
Code:
import smtplib
class Gmailer:
"""
Send email through Gmail.
use: Gmailer(user, password[, host])
use: send(to_addrs, subject, message[, from_addrs])
"""
host='smtp.gmail.com'
def __init__(self, user, password, host=None):
"""
Set Google username and passsword.
use: Gmailer(user, password[, host])
"""
self.user=user
self.password=password
if host: self.host=host
def send(self, to_addrs, subject, message, from_addr=None):
"""
Set username and passsword
use: send(to_addrs, subject, message[, from_addrs])
"""
if not from_addr: from_addr=self.user
data = "From: %s\nTo: %s\nSubject: %s\n\n%s" \
% (from_addr, to_addrs, subject, message)
try:
server=smtplib.SMTP(self.host)
[U][B] server.ehlo()
server.starttls()
server.ehlo() # This must be done before and after starttls().[/B][/U]
server.login(self.user, self.password)
server.sendmail(from_addr, to_addrs, data)
except: raise
try: server.quit() # This always fails and can safely be ignored.
except: pass
mail = Gmailer('user@gmail.com', 'mypass')
try:
mail.send('test@example.com', 'My Subject', 'This is my body!')
mail.send('test@example.net;test@example.org', 'My Subject', 'This is my body!')
except:
print "Failed."