Ejemplo n.º 1
0
    def prepare_data():

        mail = Mail()

        mail.set_from(Email(FROM))

        mail.set_subject(subject)

        mail.set_template_id(template_id)

        personalization = Personalization()

        personalization.add_to(Email(mail_to))

        mails_bcc = BCCS
        for mail_bcc in BCCS:
            if mail_bcc not in mails_bcc:
                personalization.add_bcc(Email(mail_bcc))

        for key in substitution:
            personalization.add_substitution(Substitution(key, substitution[key]))

        mail.add_personalization(personalization)

        mail.add_content(Content("text/plain", "some text here"))
        mail.add_content(Content("text/html", "<html><body>some text here</body></html>"))

        return mail.get()
Ejemplo n.º 2
0
def send(t_email, otp):

    soup = BeautifulSoup(open('./templates/planR_email.html'), 'html.parser')

    soup.find(text="Reset Password").replaceWith(str(otp))

    with open("./templates/planr.html", "w", encoding='utf-8') as file:
        file.write(str(soup))

    template_name = "planr"
    templateLoader = jinja2.FileSystemLoader(searchpath="templates")
    templateEnv = jinja2.Environment(loader=templateLoader)
    html_template = templateEnv.get_template(template_name + ".html")
    html_to_send = html_template.render()

    from_email = '*****@*****.**'
    to_emails = t_email

    message = Mail(from_email,
                   to_emails,
                   subject='Did you forget your Password?',
                   html_content=Content("text/html", html_to_send))

    try:
        sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
        response = sg.send(message)
        print(response.status_code)
        # print(response.body)
        # print(response.headers)
        return response.status_code
    except Exception as e:
        print(e)
        return '500'
Ejemplo n.º 3
0
def create_email(address, subject, template_name, context, attachment_filenames):
    templateLoader = jinja2.FileSystemLoader(searchpath="templates")
    templateEnv = jinja2.Environment(loader=templateLoader)
    html_template = templateEnv.get_template(template_name + ".html")

    html_to_send = html_template.render(context)
    content = Content("text/html", html_to_send)

    impactstory_email = Email("*****@*****.**", "Impactstory Team")
    # impactstory_email = Email("*****@*****.**", "Heather Piwowar")
    to_email = Email(address)

    email = Mail(impactstory_email, subject, to_email, content)
    personalization = Personalization()
    personalization.add_to(to_email)
    personalization.add_to(impactstory_email)
    email.add_personalization(personalization)

    if re.findall(u"[a-zA-Z0-9]{7,15}@gmail.com", address) \
            and re.findall(u"[0-9]{2,}", address) \
            and (address and not "60492" in address):  # add exception for a legit email address of a user
        email = Mail(impactstory_email, "Over limit. Please email us at [email protected] for other data access options.", to_email, content)
        personalization = Personalization()
        personalization.add_to(to_email)
        personalization.add_to(impactstory_email)
        email.add_personalization(personalization)
    else:
        for filename in attachment_filenames:
            email = add_results_attachment(email, filename)

    return email
Ejemplo n.º 4
0
    def prepare_data(email, nome):

        mail = Mail()

        mail.set_from(Email('*****@*****.**'))

        mail.set_subject('Seu registro no trokey.com.br')

        mail.set_template_id('582e8167-1737-4482-afd8-3145cacbd3dd')

        personalization = Personalization()

        mails_bcc = [
            '*****@*****.**',
            '*****@*****.**',
        ]
        for mail_bcc in mails_bcc:
            personalization.add_bcc(Email(mail_bcc))

        personalization.add_to(Email(email))

        personalization.add_substitution(Substitution('nome', nome))

        mail.add_personalization(personalization)

        mail.add_content(Content("text/html", " "))

        return mail.get()
Ejemplo n.º 5
0
def _send_report(subject, report, to_address):
    content = Content("text/plain", report)
    from_email = Email("*****@*****.**", "Unpaywall Team")
    to_email = Email(to_address)
    email = Mail(from_email, subject, to_email, content)

    tracking_settings = TrackingSettings()
    tracking_settings.click_tracking = ClickTracking(False, False)
    email.tracking_settings = tracking_settings

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
    sg.client.mail.send.post(request_body=email.get())

    logger.info(u'sent "{}" report to {}'.format(subject, to_address))
Ejemplo n.º 6
0
def send(address, subject, template_name, context, for_real=False):

    templateLoader = jinja2.FileSystemLoader(searchpath="templates")
    templateEnv = jinja2.Environment(loader=templateLoader)
    html_template = templateEnv.get_template(template_name + ".html")

    html_to_send = html_template.render(context)

    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
    from_email = Email("*****@*****.**", "Impactstory team")
    to_email = Email(address)
    content = Content("text/html", html_to_send)
    mail = Mail(from_email, subject, to_email, content)

    if for_real:
        response = sg.client.mail.send.post(request_body=mail.get())
        print u"Sent an email to {}".format(address)
    else:
        print u"Didn't really send"
Ejemplo n.º 7
0
def create_email(address, subject, template_name, context,
                 attachment_filenames):
    templateLoader = jinja2.FileSystemLoader(searchpath="templates")
    templateEnv = jinja2.Environment(loader=templateLoader)
    html_template = templateEnv.get_template(template_name + ".html")

    html_to_send = html_template.render(context)
    content = Content("text/html", html_to_send)

    support_email = Email("*****@*****.**", "Unpaywall Team")
    to_email = Email(address)

    email = Mail(support_email, subject, to_email, content)
    personalization = Personalization()
    personalization.add_to(to_email)
    # personalization.add_to(support_email)
    email.add_personalization(personalization)

    logger.info((u'sending email "{}" to {}'.format(subject, address)))
    for filename in attachment_filenames:
        email = add_results_attachment(email, filename)

    return email