def __init__(self, *args, **kwargs):
super(SendgridBackend, self).__init__(*args, **kwargs)
if "api_key" in kwargs:
self.sg = sendgrid.SendGridAPIClient(api_key=kwargs["api_key"])
elif hasattr(settings, "SENDGRID_API_KEY") and settings.SENDGRID_API_KEY:
self.sg = sendgrid.SendGridAPIClient(api_key=settings.SENDGRID_API_KEY)
else:
raise ImproperlyConfigured("settings.py must contain a value for SENDGRID_API_KEY. " +
"You may also pass a value to the api_key argument (optional).")
sandbox_mode_in_debug = True
if hasattr(settings, "SENDGRID_SANDBOX_MODE_IN_DEBUG"):
sandbox_mode_in_debug = settings.SENDGRID_SANDBOX_MODE_IN_DEBUG
self.sandbox_mode = settings.DEBUG and sandbox_mode_in_debug
if self.sandbox_mode:
warnings.warn("Sendgrid email backend is in sandbox mode! Emails will not be delivered.")
track_email = True
if hasattr(settings, "SENDGRID_TRACK_EMAIL_OPENS"):
track_email = settings.SENDGRID_TRACK_EMAIL_OPENS
self.track_email = track_email
评论列表
文章目录