Пример #1
0
def send_mail(snap_id, group_id):
    '''
    Sends an email to users specified in the group, with all the images for a supplied snap
    '''
    group_document = get_group_document(group_id)
    if ('email_recipients' in group_document and
            'send_email_contents' in group_document and
            group_document['email_recipients'] and
            group_document['send_email_contents']):
        pics_have_been_attached = False

        subject = "pictures from snap {0}".format(snap_id)
        recipients = group_document['email_recipients'].split(',')
        sender_addr = os.environ.get('MAIL_USERNAME')
        msg = Message(subject, sender=sender_addr, recipients=recipients)
        msg.body = "this is the image for snap id {0}\n\n".format(snap_id)

        pictures = search_generic(document_type='picture',
                                  args_dict={'snap_id': str(snap_id)})
        picture_types = group_document['send_email_contents'].split(',')
        for pic_id in pictures.keys():
            if pictures[pic_id]['source'] in picture_types:
                pic_name = build_picture_name(pic_id)
                pic_path = build_picture_path(picture_name=pic_name, snap_id=snap_id)

                file_contents = get_file_contents(pic_path)
                msg.attach(pic_name, "image/jpeg", file_contents)
                pics_have_been_attached = True
#                with current_app.open_resource(pic_path) as fp:
#                    msg.attach(pic_name, "image/jpeg", fp.read())
#                    pics_have_been_attached = True
        if pics_have_been_attached:
            mail.send(msg)
Пример #2
0
def send_mail(snap_id, group_id):
    """
    Sends an email to users specified in the group, with all the images for a supplied snap
    """
    group_document = get_group_document(group_id)
    if (
        "email_recipients" in group_document
        and "send_email_contents" in group_document
        and group_document["email_recipients"]
        and group_document["send_email_contents"]
    ):
        pics_have_been_attached = False

        subject = "pictures from snap {0}".format(snap_id)
        recipients = group_document["email_recipients"].split(",")
        sender_addr = os.environ.get("MAIL_USERNAME")
        msg = Message(subject, sender=sender_addr, recipients=recipients)
        msg.body = "this is the image for snap id {0}\n\n".format(snap_id)

        pictures = search_generic(document_type="picture", args_dict={"snap_id": str(snap_id)})
        picture_types = group_document["send_email_contents"].split(",")
        for pic_id in pictures.keys():
            if pictures[pic_id]["source"] in picture_types:
                pic_name = build_picture_name(pic_id)
                pic_path = build_picture_path(picture_name=pic_name, snap_id=snap_id)

                file_contents = get_file_contents(pic_path)
                msg.attach(pic_name, "image/jpeg", file_contents)
                pics_have_been_attached = True
        #                with current_app.open_resource(pic_path) as fp:
        #                    msg.attach(pic_name, "image/jpeg", fp.read())
        #                    pics_have_been_attached = True
        if pics_have_been_attached:
            mail.send(msg)
Пример #3
0
def send_mail(snap_id, group_id):
    group_document = get_group_document(group_id)
    if ('email_recipients' in group_document and 
        'send_email_contents' in group_document and
        group_document['email_recipients'] and
        group_document['send_email_contents']):
        pics_have_been_attached = False

        subject = "pictures from snap {0}".format(snap_id)
        recipients = group_document['email_recipients'].split(',')
        sender_addr = os.environ.get('MAIL_USERNAME')
        msg = Message(subject, sender=sender_addr, recipients=recipients)
        msg.body = "this is the image for snap id {0}\n\n".format(snap_id)

        pictures = find_pictures({'snap_id': str(snap_id)})
        picture_types = group_document['send_email_contents'].split(',')
        for pic_id in pictures.keys():
            if pictures[pic_id]['source'] in picture_types:
                pic_name = build_picture_name(pic_id)
                pic_path = build_picture_path(picture_name=pic_name, snap_id=snap_id)
                with current_app.open_resource(pic_path) as fp:
                    msg.attach(pic_name, "image/jpeg", fp.read())
                    pics_have_been_attached = True
        if pics_have_been_attached:
            mail.send(msg)
Пример #4
0
def send_mail(snap_id, group_id):
    group_document = get_group_document(group_id)
    if ('email_recipients' in group_document
            and 'send_email_contents' in group_document
            and group_document['email_recipients']
            and group_document['send_email_contents']):
        pics_have_been_attached = False

        subject = "pictures from snap {0}".format(snap_id)
        recipients = group_document['email_recipients'].split(',')
        sender_addr = os.environ.get('MAIL_USERNAME')
        msg = Message(subject, sender=sender_addr, recipients=recipients)
        msg.body = "this is the image for snap id {0}\n\n".format(snap_id)

        pictures = find_pictures({'snap_id': str(snap_id)})
        picture_types = group_document['send_email_contents'].split(',')
        for pic_id in pictures.keys():
            if pictures[pic_id]['source'] in picture_types:
                pic_name = build_picture_name(pic_id)
                pic_path = build_picture_path(picture_name=pic_name,
                                              snap_id=snap_id)
                with current_app.open_resource(pic_path) as fp:
                    msg.attach(pic_name, "image/jpeg", fp.read())
                    pics_have_been_attached = True
        if pics_have_been_attached:
            mail.send(msg)