def send(self, message): conn = SQLTransaction() cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cursor.execute("SELECT * FROM pim.users WHERE user_id = %s", [self.session['user_id']]) user = cursor.fetchone() conn.close() smtpConn = smtplib.SMTP("localhost") msg = MIMEMultipart() msg.set_charset("UTF-8") msg['From'] = self.sender msg['To'] = self.admin msg['Subject'] = u"Návrh na zlepšení PIM" htmlPart = MIMEText(message.encode("utf8"), 'html') msg.attach(htmlPart) smtpConn.sendmail("PIM", self.admin, msg.as_string()) smtpConn.quit() return {"status": "OK"}
def __init__(self, table, connection = None): self.table = table if connection: self.sqlConn = connection self.useTransaction = True else: self.sqlConn = SQLTransaction()
def __init__(self, userId, accountId): conn = SQLTransaction() cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cursor.execute(""" SELECT * FROM pim.imap_accounts WHERE imap_account_id = %s AND user_id = %s""", (accountId, userId)) settings = cursor.fetchone() conn.close() if settings['ssl'] == True: self.imapHandle = imaplib.IMAP4_SSL(settings['host'], settings['port']) else: self.imapHandle = imaplib.IMAP4(settings['host'], settings['port']) if settings['login']: self.login(settings['login'], settings['password']) self.attachments = {}
def sendMail(self, accountId, subject, recipients, message): conn = SQLTransaction() cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) cursor.execute(""" SELECT * FROM pim.smtp_accounts WHERE smtp_account_id = %s AND user_id = %s""", (accountId, self.session['user_id'])) settings = cursor.fetchone() conn.close() smtpConn = smtplib.SMTP(settings['host']) if settings['login']: smtpConn.login(settings['login'], settings['password']) to = ", ".join(recipients) msg = MIMEMultipart() msg.set_charset("UTF-8") msg['From'] = settings['name'] msg['To'] = to msg['Subject'] = subject htmlPart = MIMEText(message.encode("utf8"), 'html') msg.attach(htmlPart) smtpConn.sendmail(settings['name'], to, msg.as_string()) smtpConn.quit() return { 'status': "OK" }