from typing import Tuple

from opwen_email_server import azure_constants as constants
from opwen_email_server import config
from opwen_email_server.services.queue import AzureQueue
from opwen_email_server.services.sendgrid import SendgridEmailSender

QUEUE = AzureQueue(account=config.QUEUES_ACCOUNT, key=config.QUEUES_KEY,
                   name=constants.QUEUE_EMAIL_SEND)

EMAIL = SendgridEmailSender(key=config.EMAIL_SENDER_KEY)


def send(email: dict) -> Tuple[str, int]:
    success = EMAIL.send_email(email)

    if not success:
        return 'error', 500

    return 'sent', 200


if __name__ == '__main__':
    from argparse import ArgumentParser
    from json import loads
    from uuid import uuid4

    parser = ArgumentParser()
    parser.add_argument('email')
    args = parser.parse_args()

    email = loads(args.email)
    email.setdefault('_uid', str(uuid4()))

    send(email)

@@ -664,25 +664,125 @@
 rom 
-json import loads
+argparse import FileType%0A    from base64 import b64encode%0A    from json import loads%0A    from os.path import basename
 %0A   
@@ -869,16 +869,77 @@
 email')%0A
+    parser.add_argument('--attachment', type=FileType('rb'))%0A
     args
@@ -992,16 +992,16 @@
 .email)%0A
-
     emai
@@ -1036,16 +1036,266 @@
 d4()))%0A%0A
+    if args.attachment:%0A        email.setdefault('attachments', %5B%5D).append(%7B%0A            'filename': basename(args.attachment.name),%0A            'content': b64encode(args.attachment.read()).decode('ascii')%0A        %7D)%0A        args.attachment.close()%0A%0A
     send

Add attachment support to email sender CLI