Example #1
0
def forward_to_admins(message, local=None, domain=None):
    if message.is_bounce():
        # log and swallow the message
        log.warning("Detected message bounce %s, subject: %s", message, message["Subject"])
        return

    try:
        Relay().deliver(message, To=[m[1] for m in settings.ADMINS], From=settings.SERVER_EMAIL)
    except Exception as excp:
        log.exception("Error while forwarding admin message %s: %s", id(message), excp)
        raise SMTPError(450, "Error while forwarding admin message %s" % id(message))
Example #2
0
def process_message(message, inbox=None, domain=None):
    try:
        inbox = Inbox.objects.filter(inbox=inbox, domain__domain=domain)
        inbox = inbox.select_related("user", "user__inboxenprofile").receiving()
        inbox = inbox.get()

        make_email(message, inbox)

        with search.skip_index_update():
            inbox.flags.new = True
            inbox.save(update_fields=["flags"])

        if not inbox.flags.exclude_from_unified:
            profile = inbox.user.inboxenprofile
            profile.flags.unified_has_new_messages = True
            profile.save(update_fields=["flags"])

    except DatabaseError as e:
        log.exception("DB error: %s", e)
        raise SMTPError(451, "Error processing message, try again later.")
    except Inbox.DoesNotExist:
        raise SMTPError(550, "No such address")
Example #3
0
def START(message, address=None, host=None):

    # Get the email addresses and the subject prefix/tag from an API URL.
    resp = requests.get("{0}{1}".format(config["url"], address))
    data = json.loads(resp.text)

    emails = data["emails"]
    prefix = data["tag"]

    if emails is None:
        raise SMTPError(550, "Unknown address")

    subject = message["Subject"]

    # Add the prefix if not already in the subject field
    if not prefix.lower() in subject.lower():
        new_subject = "{0} {1}".format(prefix, subject)
        del message["Subject"]
        message["Subject"] = new_subject

    if len(emails) > 0:
        if any(email is None for email in emails):
            # Send back to the sender
            emails = [message["From"]]
            message = MailResponse(
                To=message["From"],
                From="*****@*****.**",
                Subject="FAILED TO SEND: {0}".format(subject),
                Body="""
                Failed to send the email.

                Some recipients don't have email addresses defined.

                The email wasn't delivered to anyone.

                Please contact the administrator for help.
                """)
        relay.deliver(message, To=emails)
    else:
        logging.debug("No receivers, not relaying the email")