Exemplo n.º 1
0
def callback(message):
  
  result = {'email': 
                  { 'raw': message.original.as_string(True),
                    'sender':message.sender, 
                    'subject':message.subject, 
                    'to': message.to,
                    'date':message.date
                    }
            }
  email = store_email_and_attachment(message, is_from_external=True)
  if not email:
    logging.error("Failed to save message: %s", 
                  message.original.as_string(True))
  
  response = fetch(settings['outbound_url'], 
              payload=json.dumps(result), 
              method="POST", 
              headers={
                'Authorization': settings['api_key'],
                'Content-Type': 'application/json'
              },
              deadline=10
             )

  logging.info(response.status_code)
  if response.status_code != 200:
    raise FetchError()
Exemplo n.º 2
0
def email(body):
  email = json.loads(body)
  logging.info(email)
  mail_message = mail.EmailMessage(**safe_dict(email))
  mail_message.send()

  #The below stores the email and any attachments
  stored_email = store_email_and_attachment(mail_message,
											is_from_external=False)
  if not stored_email:
    logging.error("Failed to save message: %s", 
                  message.original.as_string(True))