Das, was ich gemacht:
from django.core.mail import EmailMultiAlternatives
from django.template.context import Context
from django.template.loader import get_template
from smtpapi import SMTPAPIHeader
def send_email(subject, template_name, context, to, bcc=None, from_email=settings.DEFAULT_FROM_EMAIL, send_at=None):
header = SMTPAPIHeader()
body = get_template(template_name).render(Context(context))
if send_at:
send_at = {"send_at": send_at}
header.set_send_at(send_at)
email = EmailMultiAlternatives(
subject=subject,
body=body,
from_email=from_email,
to=to,
bcc=bcc,
headers={'X-SMTPAPI': header.json_string()}
)
email.attach_alternative(body, 'text/html')
email.send()
Vergessen Sie nicht, es in I-Header X-SMTPAPI Ursache einstellen konnte es nicht überall .. Und send_at sollte ein Zeitstempel
sein
auch hier konnte man sehen, wie Header oder etwas hinzufügen, aber mit sendgrid.SendGridClient: https://sendgrid.com/docs/Utilities/code_workshop.html/scheduling_parameters.html
import sendgrid
...
sg = sendgrid.SendGridClient('apiKey')
message = sendgrid.Mail()
message.add_to('John Doe <[email protected]>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')
message.set_from('Doe John <[email protected]>')
message.smtpapi.set_send_at(timestamp)
sg.send(message)
Was ist das Problem? –
Es ist die Antwort :) Ich habe es als Leitfaden hinzugefügt .. – Gvidoou
@Gvidoou als Sie sollten es als Antwort haben. Nicht in Frage. Und markieren Sie es als beantwortet danach. – Lucas03