Skip to content

Email sender

SG_FROM_EMAIL = '[email protected]' module-attribute

SG_FROM_NAME = 'Tim' module-attribute

sg_client = sendgrid.SendGridAPIClient(api_key=settings.SENDGRID_API_KEY) module-attribute

MessageValidator

Bases: BaseModel

content instance-attribute

from_email instance-attribute

subject instance-attribute

to_email instance-attribute

escape_html(value) classmethod

send_email(content, subject, to_email=None, from_email=SG_FROM_EMAIL, client=None) async

Send an email using SendGrid.

PARAMETER DESCRIPTION
content

The email content.

TYPE: str

subject

The email subject.

TYPE: str

to_email

The email recipient.

TYPE: str | None DEFAULT: None

from_email

The email to send from (note: must be verified in SendGrid first).

TYPE: str DEFAULT: SG_FROM_EMAIL

client

The SendGrid client to use.

TYPE: SendGridAPIClient | None DEFAULT: None

RAISES DESCRIPTION
ValidationError

If emails/content are invalid.

HTTPError

If SendGrid API request fails.