Пример #1
0
def send_async_email(
    session, recipients, subject, template, settings, context, send_after, async_key=None
):
    """Construct a message object from a template and schedule it

    This is the main email sending method to send out a templated email. This is used to
    asynchronously queue up the email for sending.

    Args:
        recipients (str or list(str)): Email addresses that will receive this mail. This
            argument is either a string (which might include comma separated email addresses)
            or it's a list of strings (email addresses).
        subject (str): Subject of the email.
        template (str): Name of the template to use.
        context (dict(str: str)): Context for the template library.
        settings (Settings): grouper.settings.Settings object grouper was run with
        send_after (DateTime): Schedule the email to go out after this point in time.
        async_key (str, optional): If you set this, it will be inserted into the db so that
            you can find this email in the future.

    Returns:
        Nothing.
    """
    if isinstance(recipients, string_types):
        recipients = recipients.split(",")

    msg = get_email_from_template(recipients, subject, template, settings, context)

    for rcpt in recipients:
        notif = AsyncNotification(
            key=async_key, email=rcpt, subject=subject, body=msg.as_string(), send_after=send_after
        )
        notif.add(session)
    session.commit()
Пример #2
0
def send_async_email(
    session: Session,
    recipients: Iterable[str],
    subject: str,
    template: str,
    settings: Settings,
    context: Context,
    send_after: datetime,
    async_key: Optional[str] = None,
) -> None:
    """Construct a message object from a template and schedule it

    This is the main email sending method to send out a templated email. This is used to
    asynchronously queue up the email for sending.

    Args:
        recipients: Email addresses that will receive this mail
        subject: Subject of the email.
        template: Name of the template to use.
        context: Context for the template library.
        settings: Grouper settings
        send_after: Schedule the email to go out after this point in time.
        async_key: If you set this, it will be inserted into the db so that you can find this email
            in the future.
    """
    msg = get_email_from_template(recipients, subject, template, settings, context)

    for rcpt in recipients:
        notif = AsyncNotification(
            key=async_key, email=rcpt, subject=subject, body=msg.as_string(), send_after=send_after
        )
        notif.add(session)
    session.commit()
Пример #3
0
def send_async_email(
    session,  # type: Session
    recipients,  # type: Iterable[str]
    subject,  # type: Text
    template,  # type: str
    settings,  # type: Settings
    context,  # type: Context
    send_after,  # type: datetime
    async_key=None,  # type: Optional[str]
):
    # type: (...) -> None
    """Construct a message object from a template and schedule it

    This is the main email sending method to send out a templated email. This is used to
    asynchronously queue up the email for sending.

    Args:
        recipients: Email addresses that will receive this mail
        subject: Subject of the email.
        template: Name of the template to use.
        context: Context for the template library.
        settings: Grouper settings
        send_after: Schedule the email to go out after this point in time.
        async_key: If you set this, it will be inserted into the db so that you can find this email
            in the future.

    Returns:
        Nothing.
    """
    msg = get_email_from_template(recipients, subject, template, settings, context)

    for rcpt in recipients:
        notif = AsyncNotification(
            key=async_key, email=rcpt, subject=subject, body=msg.as_string(), send_after=send_after
        )
        notif.add(session)
    session.commit()
Пример #4
0
def send_async_email(
        session, recipients, subject, template, settings, context, send_after, async_key=None):
    """Construct a message object from a template and schedule it

    This is the main email sending method to send out a templated email. This is used to
    asynchronously queue up the email for sending.

    Args:
        recipients (str or list(str)): Email addresses that will receive this mail. This
            argument is either a string (which might include comma separated email addresses)
            or it's a list of strings (email addresses).
        subject (str): Subject of the email.
        template (str): Name of the template to use.
        context (dict(str: str)): Context for the template library.
        settings (Settings): grouper.settings.Settings object grouper was run with
        send_after (DateTime): Schedule the email to go out after this point in time.
        async_key (str, optional): If you set this, it will be inserted into the db so that
            you can find this email in the future.

    Returns:
        Nothing.
    """
    if isinstance(recipients, basestring):
        recipients = recipients.split(",")

    msg = get_email_from_template(recipients, subject, template, settings, context)

    for rcpt in recipients:
        notif = AsyncNotification(
            key=async_key,
            email=rcpt,
            subject=subject,
            body=msg.as_string(),
            send_after=send_after,
        )
        notif.add(session)
    session.commit()