示例#1
0
def enviar_correo(para, asunto, plantilla, contexto, adjuntos=None):
    plaintext = get_template('correos/{}.txt'.format(plantilla))
    htmly = get_template('correos/{}.html'.format(plantilla))
    d = Context(contexto)
    text_content = plaintext.render(d)
    html_content = htmly.render(d)
    correo = EmailMultiAlternatives(asunto, text_content, '*****@*****.**',
                                    para)
    correo.attach_alternative(html_content, "text/html")
    correo.attachments = adjuntos
    correo.send()
示例#2
0
def send_mail(template, to_email, subject, context={}, attachments=None):
    try:
        body = render_to_string(template, context)
        message = EmailMultiAlternatives(subject, body, settings.DEFAULT_FROM_EMAIL, to_email)

        if attachments:
            message.attachments = attachments

        message.attach_alternative(body, "text/html")
        return {'ok': message.send()}
    except Exception as e:
        return {'error': e.args[0]}
示例#3
0
def send_email(filename, email):
    mail = EmailMultiAlternatives(
        subject="{}".format(filename),
        body="Here's your song mateio.",
        from_email="Youtube downloader <*****@*****.**>",
        to=["{}".format(email)],
        reply_to=["*****@*****.**"],
    )
    mail.template_id = 'c00b4864-3192-4650-9ca4-e83772f929d3'

    mail.attach_alternative("<p>Here's your song!</p>", "text/html")

    with open('{}'.format(filename), 'rb') as file:
        mail.attachments = [('{}'.format(filename), file.read(),
                             'application/mp3')]

    mail.send()
    def send_pdf(params):
        mail = EmailMultiAlternatives(
            subject=params['subject'],
            body=params['body'],
            from_email="The Key Keepers <*****@*****.**>",
            to=params['to'],
            headers={"Reply-To": "*****@*****.**"})
        mail.template_id = params['template_id']

        pdf = Invoice.render_to_file('invoice.html', params)

        with open(str(pdf[1]), 'rb') as file:
            mail.attachments = [(str(pdf[0]), file.read(), 'application/pdf')]

        try:
            mail.send()
        except Exception as e:
            print(e)