Api reference
components.emailing.public.blueprint ¶
EmailingBlueprint ¶
Bases: Blueprint
Source code in components/emailing/public/blueprint.py
get_campaign ¶
Source code in components/emailing/public/blueprint.py
get_non_recurring_campaign ¶
Source code in components/emailing/public/blueprint.py
get_recurring_campaign ¶
Source code in components/emailing/public/blueprint.py
get_segment ¶
get_segments ¶
get_template ¶
Source code in components/emailing/public/blueprint.py
get_templates ¶
get_webhooks ¶
list_campaigns ¶
list_non_recurring_campaigns ¶
list_recurring_campaigns ¶
register_non_recurring_campaign ¶
Source code in components/emailing/public/blueprint.py
register_recurring_campaign ¶
Source code in components/emailing/public/blueprint.py
register_segment ¶
register_template ¶
register_webhook ¶
Register a webhook handler for a given campaign name and event type. The handler will be called with the following arguments: - email_log_id: the id of the email log - event_type: the event type - timestamp: the timestamp of the event
Source code in components/emailing/public/blueprint.py
unregister_all_campaigns ¶
unregister_recurring_campaign ¶
Source code in components/emailing/public/blueprint.py
customerio_api_blueprint
module-attribute
¶
customerio_api_blueprint_record_once ¶
Source code in components/emailing/public/blueprint.py
emailing_api_blueprint
module-attribute
¶
emailing_api_blueprint_record_once ¶
Source code in components/emailing/public/blueprint.py
record_once ¶
Source code in components/emailing/public/blueprint.py
components.emailing.public.campaign ¶
get_campaigns ¶
Return list of - non-recurring campaigns that have been sent at least once between provided dates - recurring campaign that haven been registered
Uses the pre-aggregated TuringEmailStats table which contains daily stats for each campaign. The stats are already aggregated per day, per campaign, and per app.
Return a list of Campaign objects.
Source code in components/emailing/public/campaign.py
components.emailing.public.dependencies ¶
EmailingDependency ¶
get_app_dependency ¶
Gets the dependency for the emailing component.
Source code in components/emailing/public/dependencies.py
set_app_dependency ¶
Sets the dependency for the emailing component.
Source code in components/emailing/public/dependencies.py
components.emailing.public.email ¶
Campaign
dataclass
¶
EmailLogMetrics
dataclass
¶
EmailLogMetrics(
pending_count,
sent_count,
delivered_count,
failed_count,
bounced_count,
dropped_count,
skipped_count,
total_count,
opened_count,
clicked_count,
)
batch_send_email ¶
batch_send_email(
recipients,
template_name,
template_settings,
enqueue_as_draft=False,
transactional_message_id=None,
message_frequency=None,
campaign_name=None,
dry_run=False,
defer_send=True,
message_metadata=None,
account_ref=None,
sender_email_address=None,
email_priority=EmailPriority.low,
log_params=None,
)
Send email messages to a list of audience members using a registered email template. See send_email for more details.
Source code in components/emailing/public/email.py
get_email_log_metrics ¶
get_email_log_metrics(
is_dry_run=None,
account_refs=None,
sent_after=None,
sent_before=None,
campaign_names=None,
message_metadata=None,
)
Source code in components/emailing/public/email.py
paginate_email_logs ¶
paginate_email_logs(
page,
per_page=500,
email_logs_ids=None,
user_ids=None,
account_refs=None,
email_addresses=None,
template_names=None,
campaign_names=None,
is_dry_run=False,
delivery_ids=None,
has_been_sent=None,
has_been_delivered=None,
has_been_opened=None,
has_been_clicked=None,
has_failed=None,
state=None,
message_metadata=None,
sent_before=None,
sent_after=None,
)
Returns a paginated list of email logs.
:param page: The page number to return. Starts at 1. :param per_page: The number of items per page. :param email_logs_ids: Filter by email log ids. :param account_refs: Filter by account refs. :param user_ids: Filter by recipient user ids. :param is_dry_run: Keep only dry run email logs if True. :param email_addresses: Filter by recipient email addresses. :param template_names: Filter by template names ⚠️ using this args can be slow as it's not indexed for now :param campaign_names: Filter by campaign names ⚠️ using this args can be slow as it's not indexed for now :param state : Filter by email log state. :param delivery_ids: Filter by delivery ids. :param has_been_sent: Keep only sent email logs if True. :param has_been_delivered: Keep only delivered email logs if True. :param has_been_opened: Keep only opened email logs if True. :param has_been_clicked: Keep only clicked email logs if True. :param has_failed: Keep only failed email logs if True. :param sent_before: Filter by sent date before. :param sent_after: Filter by sent date after. :param message_metadata: Filter by message metadata.
Source code in components/emailing/public/email.py
preview_email ¶
Preview an email using a registered email template.
Source code in components/emailing/public/email.py
send_email ¶
send_email(
recipient,
template_name=None,
template_settings=None,
campaign_name=None,
transactional_message_id=None,
message_metadata=None,
message_frequency=None,
account_ref=None,
sender_email_address=None,
enqueue_as_draft=False,
async_send=False,
defer_send=False,
silent_failure=False,
dry_run=False,
log_params=None,
email_priority=EmailPriority.low,
)
Send email to a recipient address using a registered email template.
:param recipient: The recipient of the email defined by its user_id (required for customerio), email address and user context (provided to the template to customise the email content).
:param template_name: Template name of the template to be retrieved from the template registry and use to render the email. It should not be used with template_uri.
:param template_settings: Settings that will be used to customise template rendering. Those settings will be provided to the template got from the template registry. Ignored if template_uri & template data are provided.
:param transactional_message_id: optional transactional message id that will be used to send the email through the email provider. If not provided, the default transactional message id will be used.
:param campaign_name: identifies a group of messages together. For instance, it's used to register webhooks that will be called when events are received for this campaign.
:param message_metadata: optional metadata that will be persisted in the email log
:param dry_run: if True, the email will not be sent and email log won't be created. If async_send is True, the email will be enqueued anyway.
:param enqueue_as_draft: if True, the email will be enqueued as draft in the CRM and won't be sent. The email log will be created anyway, flag as sent
:param account_ref: optional account reference to log this email in the context of an account.
:param sender_email_address: optional sender email address that will be used to send the email. Defaults to config["EMAIL_SENDER_NAME"] if None.
:param message_frequency: optional frequency limit that will be used to manage the number of emails sent to a user.
:param async_send: If True, the email will be enqueued in the queue and sent asynchronously. Queues depend on the email_priority. If False, the email will be sent synchronously.
:param defer_send: Defer the send email using side effect stack. This requires to be executed through a side_effect context manager that manage the side effect. It's True by default to force consumer to explicitly handle the side effect.
:param silent_failure: If True, any exception will be caught and logged (email log success=False is created). If False the exception will be raised.
:param log_params: Additional parameters to log (current_logger)
:param email_priority: The priority of the email. It can be high or low. High priority emails are sent in priority
This method acquires a lock on the recipient to prevent multiple emails being sent to the same recipient at the same time. Thus preventing race conditions that could lead to sending more emails than the message frequency allows.
:return: The delivery id of the email if it was sent synchronously, None otherwise.
Source code in components/emailing/public/email.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
send_email_raw ¶
Send email to a recipient address providing a raw email request that you can build yourself.
:param request: The email request to send
Source code in components/emailing/public/email.py
components.emailing.public.entities ¶
audience ¶
campaign ¶
Campaign
dataclass
¶
Campaign(
campaign_name,
template_cls,
segment_cls,
app_name,
tags=list(),
sending_options=EmailSendingOptions(),
legacy_mailer=None,
is_recurring=False,
)
Bases: DataClassJsonMixin, ABC
This class defines a campaign which is a way to send email.
on_email_bounced ¶
on_email_clicked ¶
on_email_delivered ¶
on_email_dropped ¶
on_email_opened ¶
on_email_requested ¶
on_email_sent ¶
on_shoot_completed ¶
This method should be called when a shoot is completed (all emails have been tried to be sent).
on_shoot_scheduled ¶
This method should be called when a shoot is scheduled.
on_shoot_skipped ¶
on_webhook_received ¶
This method should be called when an event is received for a shoot.
Source code in components/emailing/public/entities/campaign.py
sending_options
class-attribute
instance-attribute
¶
EmailShootConfig
dataclass
¶
EmailShootConfig(
config_id,
scheduled_at,
audience,
message_frequency,
template_settings=dict(),
metadata=dict(),
state=EmailShootState.pending,
custom_blocks_variation_id=None,
sender_email_address=None,
manual_send_only=False,
)
An EmailShootConfig is a non persisted object that defines how an email shoot should be sent. You can see it as a recipe or a promise of a shoot. This is used by the recurring campaign when generating future shoots through planning.
This class encapsulates all the necessary settings and parameters required to configure and execute it, including scheduling, audience targeting, message frequency, and template customization.
:param config_id: A unique identifier for this shoot configuration.
:param scheduled_at: The date and time when the email shoot should be executed
:param audience: The target audience for this email shoot, defining who should receive the emails
:param message_frequency: Controls how often messages can be sent to the same recipient
:param template_settings: A dictionary containing custom settings for the email template
:param metadata: Additional metadata associated with this shoot configuration. Can be used to store arbitrary key-value pairs for tracking or reference
:param state: The current state of the email shoot (pending by default but you can control it)
:param custom_blocks_variation_id: Optional identifier for custom block variations in the email template. Used to test different versions of email content
:param sender_email_address: The email address that will appear as the sender. If None, defaults to the value in config["EMAIL_SENDER_NAME"]
:param manual_send_only: If True, the automatic sending of the shoot will be disabled. The shoot will wait for a manual intervention to be sent.
template_settings
class-attribute
instance-attribute
¶
Planning
dataclass
¶
get_shoots ¶
This method returns the list of shoots that match the given states and is_persisted value.
Source code in components/emailing/public/entities/campaign.py
RecurringCampaign
dataclass
¶
RecurringCampaign(
campaign_name,
template_cls,
segment_cls,
app_name,
tags=list(),
sending_options=EmailSendingOptions(),
legacy_mailer=None,
is_recurring=True,
enabled=True,
)
Bases: Campaign
This class defines a recurring campaign which is a way to send email regularly based on a recurrence rule, an audience, a template and a shoot planning definition.
cancel_shoot_config ¶
complete_shoot_config ¶
get_shoot_configs
abstractmethod
¶
This method should return the list of shoot configurations to be sent between the given dates.
Source code in components/emailing/public/entities/campaign.py
patch_shoot_config ¶
Source code in components/emailing/public/entities/campaign.py
custom_block ¶
email ¶
EmailContent
dataclass
¶
EmailContent(
subject,
body,
pre_header,
attachments,
template_data,
template,
user_context,
template_settings,
)
This class represents the content of an email. It also contains the data that has been used to render the HTML template.
An email content is created from an email template, a user_ref, a user_context and a template settings.
EmailLog
dataclass
¶
EmailLog(
email_log_ref,
user_id,
email_address,
state,
template_name,
user_context,
message_metadata,
delivery_id,
success,
sent_at,
delivered_at,
bounced_at,
dropped_at,
clicked,
opened,
created_at,
error_message,
error_type,
opened_at,
campaign_name,
attachment_filenames,
recipient_type,
is_dry_run,
account_ref,
template_settings,
)
This class represents an email log. It is used to provide information about an email that has been sent.
from_model
classmethod
¶
Source code in components/emailing/public/entities/email.py
EmailLogState ¶
Bases: AlanBaseEnum
This class represents the state of an email log. States are exclusive and represent the status of an email.
:param delivered: We received a webhook from the email provider that the email was delivered :param sent: We successfully generated and sent the email within the email provider :param failed: We failed to generate and send the email within the email provider :param bounced: We received a webhook from the email provider that the email bounced :param dropped: We received a webhook from the email provider that the email was dropped :param skipped: We skipped sending the email because generator raised a SkippingEmailSendingException especially used when the user message limit is reached :param pending: The email is pending to be sent, either because it's in the queue or because it's in dry run mode
EmailRequest
dataclass
¶
EmailRequest(
recipient,
content,
sending_options,
campaign_name=None,
message_metadata=None,
message_frequency=None,
account_ref=None,
)
EmailSendingOptions
dataclass
¶
EmailSendingOptions(
send_to_unsubscribed=True,
tracked=True,
disable_message_retention=False,
queue_draft=False,
message_id=None,
sender_email_address=None,
dry_run=False,
)
default_message_id
staticmethod
¶
MessageFrequency
dataclass
¶
Bases: DataClassJsonMixin
This class defines the message limit settings to manage the number of emails sent to a user.
:param idempotency_key: The idempotency key used to identify the message. If None, all user message will be considered for the limit. This key will always be used in addition to the user id. :param message_limit: The limit of messages that can be sent to a user. If None, no limit will be applied.
Example
Prevent multiple message for same template to be sent to a user¶
limit_settings = LimitSettings(idempotency_key="my_email_template_name", limit=1)
Prevent too many messages to be sent to a user (more than 3)¶
limit_settings = LimitSettings(limit=3)
__post_init__ ¶
Source code in components/emailing/public/entities/email.py
scoped_to_campaign
staticmethod
¶
Use this method unless you want a limit that applies cross campaigns.
Source code in components/emailing/public/entities/email.py
error ¶
EmailingErrorCode ¶
Bases: BaseErrorCode
Represents a business errors (and not technical ones) If raised - it returns 4xx if HTTP context (no sentry) - it still make jobs failed in async context (if not caught)
template_settings_not_found
staticmethod
¶
Error raised when a required key is missing in template settings when rendering an email
Source code in components/emailing/public/entities/error.py
recipient ¶
EmailRecipient
dataclass
¶
EmailRecipient(
user_ref,
email_address,
user_context=dict(),
recipient_type=RecipientType.member,
)
Bases: DataClassJsonMixin
This class represents a member of an audience. It is used to provide information to send email to a specific user.
:param user_ref: The user id of the audience member :param email_address: The email address of the audience member :param user_context: The user context of the audience member
segment ¶
Audience
dataclass
¶
Audience is list the users that will receive an email. It is defined by a segment and settings to filter the segment.
__eq__ ¶
Source code in components/emailing/public/entities/segment.py
list_recipients ¶
Source code in components/emailing/public/entities/segment.py
paginate_recipients ¶
Source code in components/emailing/public/entities/segment.py
Segment ¶
Bases: ABC
This class defines a segment. It is used to provide a list of audience members
Example
class MySegment(Segment): name = "my_segment"
def get_query(self, settings: dict, limit: int | None = None) -> Query:
return User.query.filter(User.is_active == True)
def to_recipient(self, model: User) -> EmailRecipient:
return EmailRecipient(
user_ref=model.id,
email_address=model.email,
user_context={"account_ref": model.account_ref},
)
shoot ¶
EmailShoot
dataclass
¶
EmailShoot(
shoot_id,
scheduled_at,
state,
started_at,
cancelled_at,
completed_at,
updated_at,
recipient_count,
sent_count,
delivered_count,
opened_count,
clicked_count,
failed_count,
audience,
template,
template_settings,
campaign_name,
sender_email_address,
message_frequency,
transactional_message_id,
enqueue_as_draft,
dry_run,
metadata,
is_persisted,
app_name,
tags=list(),
custom_blocks_variation_id=None,
manual_send_only=True,
)
This class represents an email shoot. It is used to schedule email sending.
A scheduled shoot is about sending messages (emails) defined by a template to a segment of users defined by an audience. The audience is defined by a segment and settings to filter the segment.
from_model
classmethod
¶
Source code in components/emailing/public/entities/shoot.py
SkippingEmailSendingException ¶
Bases: Exception
This exception should be raised when an email should not be sent.
template ¶
CustomerioManagedEmailTemplate ¶
Bases: EmailTemplate
This class defines a customerio-managed email template. It means that the HTML file is hosted in customerio
generate_email_content ¶
Source code in components/emailing/public/entities/template.py
EmailDataGenerator ¶
Bases: ABC, Generic[U]
This class defines a data generator. It is used to provide the data to render an email template. Data template should be provided by a class that inherits from TemplateData. It should provide data no matter the template is self-managed or cio-managed
get_attachments ¶
Attachments should be provided as a dict with the filename as key and the content as value,
or as a list of dict with the filename, content as keys.
Source code in components/emailing/public/entities/template.py
get_template_data
abstractmethod
¶
EmailTemplate ¶
SelfManagedEmailTemplate ¶
Bases: EmailTemplate
This class defines a self-managed email template. It means that the HTML file is hosted in our backend stored in the template file uri. It relies on a generator to provide the data to render the template.
It should also implement a method to provide the subject of the email.
The subclasses of this class should be registered using the register_template function.
:param title: The title of the template :param name: The unique name of the template :param uri: The uri of the HTML template file :param generator: The generator that will provide the data to render the template
__eq__ ¶
generate_email_content ¶
Source code in components/emailing/public/entities/template.py
get_body ¶
This method should return the body of the email
Source code in components/emailing/public/entities/template.py
get_pre_header ¶
get_subject ¶
This method should return the subject of the email that should be defined as a jinja block in the HTML template file by default
Source code in components/emailing/public/entities/template.py
TemplateData ¶
Bases: DataClassJsonMixin
This class should represent the data that will be used to render the HTML template.
TemplateSettings ¶
Bases: dict[str, Any]
A wrapper around template settings dictionary to safely handle missing keys. Inherits from dict to maintain backward compatibility with existing code.
Initialize the TemplateSettings object with the provided settings.
Source code in components/emailing/public/entities/template.py
__getitem__ ¶
Get a required value from template settings, raising a business error if missing.
Source code in components/emailing/public/entities/template.py
components.emailing.public.enums ¶
EmailShootEvent ¶
Bases: AlanBaseEnum
Enumeration for the different events of an email shoot.
EmailShootState ¶
Bases: AlanBaseEnum
Enumeration for the different states of an email shoot.
States
- pending: Shoot not yet created but only configured defined through recurring campaign.
- scheduled: Shoot is created and scheduled to be sent.
- sending: Shoot is being sent (send_shoot has been called).
- completed: All emails have been tried to be sent (completed does not mean all emails have been sent or delivered).
- cancelled: Shoot has been cancelled and won't be sent.
- skipped: Shoot is skipped when audience is empty.
components.emailing.public.events ¶
EmailLogEvent ¶
event_handler
module-attribute
¶
event_handler = EventHandler(
supported_events=[
shoot_completed,
shoot_skipped,
shoot_scheduled,
]
)
register_email_log_event ¶
Source code in components/emailing/public/events.py
register_event ¶
Register an event handler for the given event name.
unregister_event ¶
Unregister an event handler for the given event name
components.emailing.public.recurring ¶
cancel_shoot_config ¶
Source code in components/emailing/public/recurring.py
get_pending_shoot ¶
Source code in components/emailing/public/recurring.py
get_planning ¶
get_planning(
campaign_name,
before,
after,
account_refs=None,
user_ids=None,
config_id=None,
states=None,
limit=None,
)
Returns the planning of a recurring campaign
:param campaign_name: The name of the recurring campaign to get the planning from :param config_id: The config_id to filter the planning on :param account_refs: The account_refs to filter the planning on :param user_ids: The user_ids to filter the planning on :param before: Maximum date of the planning. Required. Avoid datetime.max() to avoid performance issues. :param after: Minimum date of the planning :param states: The shoot states to filter the planning on :param limit: Limit
Source code in components/emailing/public/recurring.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
patch_shoot_config ¶
patch_shoot_config(
campaign_name,
config_id,
scheduled_at=NOT_SET,
custom_blocks_variation_id=NOT_SET,
commit=True,
)
Source code in components/emailing/public/recurring.py
process_pending_shoots ¶
process_pending_shoots(
on_date,
backfill_days=0,
campaign_name=None,
account_ids=None,
user_ids=None,
silent_failure=True,
commit=True,
)
Schedule and send all shoots that need to be sent for recurring campaigns.
Source code in components/emailing/public/recurring.py
resume_shoot_config ¶
Source code in components/emailing/public/recurring.py
schedule_pending_shoots ¶
schedule_pending_shoots(
scheduled_before,
scheduled_after=None,
backfill_days=None,
campaign_name=None,
account_ids=None,
user_ids=None,
silent_failure=True,
commit=True,
)
Schedule all pending shoots for a recurring campaign at the given date.
Schedule only if the campaign is enabled.
:param campaign_name: The name of the recurring campaign to process :param scheduled_before: The date to process the recurring campaign on :param scheduled_after: The date to start the backfill from :param backfill_days: The number of days to backfill. If 0, only the shoots that are scheduled on the given date will be sent (if not already sent). :param silent_failure: If True, the function will not raise an exception if a shoot fails to be sent only logs :param account_ids: The account_refs to filter the planning on :param user_ids: The user_ids to filter the planning on :param commit: If True, the shoots will be scheduled and shoot.
Source code in components/emailing/public/recurring.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
shoot_from_config ¶
Source code in components/emailing/public/recurring.py
components.emailing.public.registry ¶
get_campaign ¶
get_non_recurring_campaign ¶
Source code in components/emailing/public/registry.py
get_recurring_campaign ¶
Source code in components/emailing/public/registry.py
get_segment ¶
get_template ¶
has_campaign ¶
has_non_recurring_campaign ¶
has_recurring_campaign ¶
has_segment ¶
has_template ¶
list_campaigns ¶
list_non_recurring_campaigns ¶
list_recurring_campaigns ¶
list_templates ¶
load_all_models ¶
Source code in components/emailing/public/registry.py
register_non_recurring ¶
Register a non-recurring campaign to be used by the emailing service.
Source code in components/emailing/public/registry.py
register_recurring ¶
Decorator to register a recurring campaign to be used by the emailing service.
Source code in components/emailing/public/registry.py
register_segment ¶
Decorator to register a segment to be used by the emailing service.
Example: class MySegment(Segment): ...
Source code in components/emailing/public/registry.py
register_template ¶
Decorator to register an email template to be used by the emailing service. Example: @register_template class MyTemplate(SelfManagedEmailTemplate): field = "value"
Source code in components/emailing/public/registry.py
register_webhook ¶
Decorator to register a webhook to be called when an event is triggered.
Example
@register_webhook("my_campaign") def my_webhook(email_log: EmailLog, event_type: EventType, occurred_at: datetime]) -> None: if event_type == EventType.SENT: ... ...
Source code in components/emailing/public/registry.py
unregister_all_campaigns ¶
unregister_recurring ¶
components.emailing.public.shoot ¶
batch_send_shoot ¶
batch_send_shoot(
shoot_ids=None,
scheduled_before=None,
scheduled_after=None,
campaign_name=None,
backfill_days=None,
commit=True,
async_shoot_send=True,
)
Batch send all scheduled shoots that match the given criteria.
:param shoot_ids: Send only these shoots :param scheduled_before: Send shoots scheduled before this date :param scheduled_after: Send shoots scheduled after this date. Cannot be used with backfill_days :param campaign_name: Only send shoots for this campaign :param backfill_days: Number of days to look back for shoots to send. Cannot be used with scheduled_after :param commit: Whether to commit the changes to the database :param async_shoot_send: Whether to process shoots asynchronously :raises ValueError: If both backfill_days and scheduled_after are provided
Source code in components/emailing/public/shoot.py
cancel_shoot ¶
Cancel an email shoot
Source code in components/emailing/public/shoot.py
duplicate_shoot ¶
Duplicate an email shoot
Source code in components/emailing/public/shoot.py
get_email_logs ¶
Source code in components/emailing/public/shoot.py
get_preview_shoot_url ¶
Generate a preview shoot url for a given template and audience It requires a flask app to be running Returns None if the url cannot be generated
Source code in components/emailing/public/shoot.py
get_shoot ¶
has_shoot ¶
list_shoots ¶
list_shoots(
shoot_ids=None,
scheduled_before=None,
scheduled_after=None,
campaign_name=None,
limit=None,
states=None,
metadata=None,
account_refs=None,
user_ids=None,
tags=None,
)
Source code in components/emailing/public/shoot.py
patch_shoot ¶
patch_shoot(
shoot_id,
scheduled_at=NOT_SET,
segment=NOT_SET,
audience_settings=NOT_SET,
template=NOT_SET,
template_settings=NOT_SET,
tags=NOT_SET,
audience_limit=NOT_SET,
campaign_name=NOT_SET,
message_frequency=NOT_SET,
transactional_message_id=NOT_SET,
metadata=NOT_SET,
enqueue_as_draft=NOT_SET,
custom_blocks_variation_id=NOT_SET,
commit=True,
)
Patch an email shoot. It only edits the shoot if the parameter is not None
Source code in components/emailing/public/shoot.py
schedule_shoot ¶
schedule_shoot(
scheduled_at,
audience,
template,
template_settings,
tags=None,
campaign_name=None,
message_frequency=None,
transactional_message_id=None,
custom_blocks=None,
metadata=None,
enqueue_as_draft=False,
shoot_id=None,
sender_email_address=None,
dry_run=False,
commit=True,
send_if_scheduled_in_past=True,
_async_send=True,
)
Schedule an email shoot at a given time
:param scheduled_at: The time at which the shoot should be sent. If in the past, the shoot will be sent immediately async. :param audience: The audience to use :param template: Template to use :param template_settings: The settings to use to render the template :param tags: The tags to add to the shoot :param message_frequency: The optional limit settings that will be used to manage the number of emails max sent to a user. :param transactional_message_id: The optional transactional message id that will be used to send the email :param campaign_name: Identifies a group of messages. This is used to trigger the right webhooks :param custom_blocks: The optional custom blocks to adapt the email content :param metadata: The optional metadata to add to the shoot :param shoot_id: The optional shoot id to use else a new one will be generated :param sender_email_address: optional sender email address that will be used to send the email. Defaults to config["EMAIL_SENDER_NAME"] if None. :param enqueue_as_draft: If True, the shoot will enqueue message as a draft when sending :param commit: If True, the shoot will be persisted in the database :param dry_run: If True, the shoot will not be sent but will be persisted in the database and email log will be created :param send_if_scheduled_in_past: If True, the shoot will be sent immediately if scheduled in the past :param _async_send: If True, the shoot will be sent async if it needs to be sent immediately
:return: The scheduled shoot
Source code in components/emailing/public/shoot.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
send_shoot ¶
Send an email shoot to its audience.
:param shoot_id id of the shoot to send :param dry_run If not dry run, the shoot will be marked as sending then completed when all the emails have been processed. :param enqueue_as_draft If True, the shoot will enqueue message as a draft when sending. If False it will send If None we let customer.io decides. :param is_retry If True, the shoot will be rescheduled (state set back to scheduled) before being sent
Source code in components/emailing/public/shoot.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
components.emailing.public.testing ¶
factories ¶
CustomBlockFactory ¶
Bases: AlanBaseFactory['CustomBlock']
EmailShootConfigFactory ¶
Bases: Factory
audience
class-attribute
instance-attribute
¶
message_frequency
class-attribute
instance-attribute
¶
message_frequency = MessageFrequency(
message_limit=1,
idempotency_params={
"campaign_name": "recurring_campaign_name",
"company_id": "1234",
},
)
template_settings
class-attribute
instance-attribute
¶
EmailShootSQLAFactory ¶
Bases: AlanBaseFactory['EmailShoot']
TuringEmailStatsFactory ¶
Bases: AlanBaseFactory['TuringEmailStats']
mock ¶
EmailLogMock ¶
Source code in components/emailing/public/testing/mock.py
MailerMock ¶
Source code in components/emailing/public/testing/mock.py
assert_any_email_sent ¶
Assert that at least an email has been sent with the given properties
Source code in components/emailing/public/testing/mock.py
assert_email_not_sent ¶
Assert that no email has been sent with the given properties
Source code in components/emailing/public/testing/mock.py
assert_email_sent ¶
assert_email_sent(
user_id=None,
email=None,
body=None,
not_body=None,
subject=None,
index=None,
transactional_message_id=None,
attachments_count=None,
)
Assert the nth email sent defined by index args has been set with the given property
Source code in components/emailing/public/testing/mock.py
assert_email_sent_count ¶
assert_single_email_sent ¶
assert_single_email_sent(
user_id=None,
email=None,
body=None,
not_body=None,
subject=None,
transactional_message_id=None,
attachments_count=None,
)