def send_email(form): mandrill = Mandrill(pqr) mandrill.send_email( from_email='*****@*****.**', subject=form['subject'], to=[{ 'email': pqr.config['DEFAULT_EMAIL'] }, { 'email': '*****@*****.**' }], text=form['subject'] + "\n" + "From: " + form['email'] + "\n" + form['message'], html=render_template("email/contact.html", date=datetime.now().strftime('%Y/%m/%d %H:%M:%S'), name=form['name'], email=form['email'], subject=form['subject'], message=form['message']), ) flash("Message has been sent!", 'sent')
def send_email(config, email, subject, body): print 'sending email to %s (%s)' % (email, subject) if config.email.use_mandrill: if isinstance(email, basestring): to = [{'email': email}] else: to = [] for addr in email: to.append({'email': addr}) import flask from flask.ext.mandrill import Mandrill mandrill = Mandrill(flask.current_app) mandrill.send_email(subject=subject, to=to, text=body) else: import smtplib from email.mime.text import MIMEText if isinstance(email, basestring): to = email else: to = ', '.join(email) # Create a text/plain message msg = MIMEText(body) msg['Subject'] = subject msg['From'] = config.email.from_ msg['To'] = to # Send the message via our own SMTP server, but don't include the # envelope header. s = smtplib.SMTP(config.email.smtp) if config.email.use_auth: s.starttls() s.login(config.email.user, config.email.password) s.sendmail(config.email.from_, [email], msg.as_string()) s.quit()
import base64 from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from flask import Flask, render_template, redirect, url_for from flask.ext.mail import Mail, Message from subprocess import call from flask.ext.mandrill import Mandrill manager = Manager(app) mail_ext = Mail(app) app.config['MANDRILL_API_KEY'] = 'rgN2mMD61Fma_qLk7Uf6jw' app.config['MANDRILL_DEFAULT_FROM'] = '*****@*****.**' mandrill = Mandrill(app) RECEIPTS_DIR = "/home/infodigital/tax-receipts/" # From http://flask.pocoo.org/snippets/68/ def create_pdf(pdf_data, pdf_file_name): html_file_name = "tax_mail.html" temphtmlfile = open(html_file_name, "w") temphtmlfile.write(pdf_data) temphtmlfile.close() call("/usr/local/bin/wkhtmltopdf " + html_file_name + " " + RECEIPTS_DIR + pdf_file_name, shell=True)