Created
March 16, 2011 15:17
-
-
Save rochacbruno/872645 to your computer and use it in GitHub Desktop.
Sobrecarga na classe Mail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### MODEL | |
from gluon.tools import * | |
######################################################################## | |
# Sobrecarga do método send da classe Mail | |
######################################################################## | |
class Mail(Mail): | |
def send( | |
self, | |
to, | |
subject='None', | |
message='None', | |
): | |
import smtplib | |
fromaddr = self.settings.sender | |
username = self.settings.login.split(':')[0] | |
password = self.settings.login.split(':')[1] | |
server = smtplib.SMTP(self.settings.server) | |
if self.settings.tls: | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
header = 'To:' + to + '\n' + 'From: ' + fromaddr + '\n' + 'Subject: '+ subject +'\n' | |
fullmsg = header + '\n' + message | |
server.login(username,password) | |
server.sendmail(fromaddr,to, fullmsg) | |
server.quit() | |
######################################################################## | |
# Fim da Sobrecarga do método send da classe Mail | |
######################################################################## | |
mail = Mail() # mailer | |
auth = Auth(globals(),db) # authentication/authorization | |
crud = Crud(globals(),db) # for CRUD helpers using auth | |
service = Service(globals()) # for json, xml, jsonrpc, xmlrpc, amfrpc | |
plugins = PluginManager() | |
mail.settings.tls = True # apenas para gmail | |
mail.settings.server = 'smtp.gmail.com:587' # your SMTP server | |
mail.settings.sender = '[email protected]' # your email | |
mail.settings.login = 'seulogin:seupassword' # your credentials or None | |
### CONTROLLER | |
def sendmail(): | |
result = mail.send('[email protected]','Testando','Olá estou testando o email') | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OMG, almost 10 year ago.. the code was so bad!!!!