Beispiel #1
0
def no_recipient_has_cc_bcc():
    m = Message()
    m.set_sender('*****@*****.**', 'Regular Sender')
    m.add_cc('*****@*****.**', 'Mario Dimitrov')
    m.add_bcc('*****@*****.**')
    m.text = "Just spam"
    return m
Beispiel #2
0
def no_recipient_has_cc_bcc():
    m = Message()
    m.set_sender('*****@*****.**', 'Regular Sender')
    m.add_cc('*****@*****.**', 'Mario Dimitrov')
    m.add_bcc('*****@*****.**')
    m.text = "Just spam"
    return m
Beispiel #3
0
def no_content_message():
    m = Message()
    m.set_sender('*****@*****.**', 'Regular Sender')
    m.subject = "Very important"
    m.add_recipient('other.userdomain.com', 'Regular Recipient')
    m.add_cc('*****@*****.**', 'Mario Dimitrov')
    m.add_bcc('*****@*****.**')
    return m
Beispiel #4
0
def no_content_message():
    m = Message()
    m.set_sender('*****@*****.**', 'Regular Sender')
    m.subject = "Very important"
    m.add_recipient('other.userdomain.com', 'Regular Recipient')
    m.add_cc('*****@*****.**', 'Mario Dimitrov')
    m.add_bcc('*****@*****.**')
    return m
Beispiel #5
0
def send_mail():
    """
    Tries to construct a message from the passed arguments,
    validates it and passes it to the MessageService for sending
    :return: Success status and result message
    In case the message did not fulfill the criteria returns a message with the first failure
    Read more at
    https://github.com/mariodmtrv/RobustMail/wiki#send-a-message
    """
    data = request.get_json()
    message = Message()
    if "sender" in data and data["sender"] is not None:
        result = gen_email_user(data["sender"])
        if result is not None:
            message.set_sender(result[0], result[1])
    if "subject" in data and data["subject"] is not None:
        message.subject = data["subject"]
    if "text" in data and data["text"] is not None:
        message.text = data["text"]
    if "recipients" in data and data["recipients"] is not None and len(
            data["recipients"]) > 0:
        for recipient in data["recipients"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_recipient(result[0], result[1])
    if 'cc' in data and data["cc"] is not None and len(data["cc"]) > 0:
        for recipient in data["cc"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_cc(result[0], result[1])
    if "bcc" in data and data["bcc"] is not None and len(data["bcc"]) > 0:
        for recipient in data["bcc"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_bcc(result[0], result[1])
    if "body" in data and data["body"] is not None:
        message.body = data["body"]
    is_valid = message.validate()
    if not is_valid[0]:
        return SendEmailResponse(is_valid[0], is_valid[1]).to_JSON()
    result = send_message.delay(message_service, message)
    return SendEmailResponse(True,
                             "Message accepted for processing!").to_JSON()
Beispiel #6
0
def send_mail():
    """
    Tries to construct a message from the passed arguments,
    validates it and passes it to the MessageService for sending
    :return: Success status and result message
    In case the message did not fulfill the criteria returns a message with the first failure
    Read more at
    https://github.com/mariodmtrv/RobustMail/wiki#send-a-message
    """
    data = request.get_json()
    message = Message()
    if "sender" in data and data["sender"] is not None:
        result = gen_email_user(data["sender"])
        if result is not None:
            message.set_sender(result[0], result[1])
    if "subject" in data and data["subject"] is not None:
        message.subject = data["subject"]
    if "text" in data and data["text"] is not None:
        message.text = data["text"]
    if "recipients" in data and data["recipients"] is not None and len(data["recipients"]) > 0:
        for recipient in data["recipients"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_recipient(result[0], result[1])
    if 'cc' in data and data["cc"] is not None and len(data["cc"]) > 0:
        for recipient in data["cc"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_cc(result[0], result[1])
    if "bcc" in data and data["bcc"] is not None and len(data["bcc"]) > 0:
        for recipient in data["bcc"]:
            result = gen_email_user(recipient)
            if result is not None:
                message.add_bcc(result[0], result[1])
    if "body" in data and data["body"] is not None:
        message.body = data["body"]
    is_valid = message.validate()
    if not is_valid[0]:
        return SendEmailResponse(is_valid[0], is_valid[1]).to_JSON()
    result = send_message.delay(message_service, message)
    return SendEmailResponse(True, "Message accepted for processing!").to_JSON()