def post(self, request): token = request.POST['token'] signature = request.POST['signature'] timestamp = request.POST['timestamp'] if not settings.MAILGUN_API_KEY: logging.error('MAILGUN_API_KEY is not set') return HttpResponse(status=500) if not self.verify(settings.MAILGUN_API_KEY, token, timestamp, signature): logging.info('Unable to verify signature for mailgun request') return HttpResponse(status=403) to_email = parseaddr(request.POST['To'])[1] from_email = parseaddr(request.POST['From'])[1] try: group_id = email_to_group_id(to_email) except Exception: logging.info('%r is not a valid email address', to_email) return HttpResponse(status=500) payload = EmailReplyParser.parse_reply( request.POST['body-plain']).strip() if not payload: # If there's no body, we don't need to go any further return HttpResponse(status=200) process_inbound_email.delay(from_email, group_id, payload) return HttpResponse(status=201)
def post(self, request): token = request.POST["token"] signature = request.POST["signature"] timestamp = request.POST["timestamp"] key = options.get("mail.mailgun-api-key") if not key: logger.error("mailgun.api-key-missing") return HttpResponse(status=500) if not self.verify(key, token, timestamp, signature): logger.info( "mailgun.invalid-signature", extra={"token": token, "timestamp": timestamp, "signature": signature}, ) return HttpResponse(status=200) to_email = request.POST["recipient"] from_email = request.POST["sender"] try: group_id = email_to_group_id(to_email) except Exception: logger.info("mailgun.invalid-email", extra={"email": to_email}) return HttpResponse(status=200) payload = EmailReplyParser.parse_reply(request.POST["body-plain"]).strip() if not payload: # If there's no body, we don't need to go any further return HttpResponse(status=200) process_inbound_email.delay(from_email, group_id, payload) return HttpResponse(status=201)
def post(self, request): token = request.POST['token'] signature = request.POST['signature'] timestamp = request.POST['timestamp'] key = options.get('mail.mailgun-api-key') if not key: logging.error('mail.mailgun-api-key is not set') return HttpResponse(status=500) if not self.verify(key, token, timestamp, signature): logging.info('Unable to verify signature for mailgun request') return HttpResponse(status=403) to_email = parseaddr(request.POST['To'])[1] from_email = parseaddr(request.POST['From'])[1] try: group_id = email_to_group_id(to_email) except Exception: logging.info('%r is not a valid email address', to_email) return HttpResponse(status=500) payload = EmailReplyParser.parse_reply(request.POST['body-plain']).strip() if not payload: # If there's no body, we don't need to go any further return HttpResponse(status=200) process_inbound_email.delay(from_email, group_id, payload) return HttpResponse(status=201)
def post(self, request): token = request.POST['token'] signature = request.POST['signature'] timestamp = request.POST['timestamp'] key = options.get('mail.mailgun-api-key') if not key: logger.error('mailgun.api-key-missing') return HttpResponse(status=500) if not self.verify(key, token, timestamp, signature): logger.info( 'mailgun.invalid-signature', extra={ 'token': token, 'timestamp': timestamp, 'signature': signature, } ) return HttpResponse(status=200) to_email = request.POST['recipient'] from_email = request.POST['sender'] try: group_id = email_to_group_id(to_email) except Exception: logger.info( 'mailgun.invalid-email', extra={ 'email': to_email, } ) return HttpResponse(status=200) payload = EmailReplyParser.parse_reply(request.POST['body-plain']).strip() if not payload: # If there's no body, we don't need to go any further return HttpResponse(status=200) process_inbound_email.delay(from_email, group_id, payload) return HttpResponse(status=201)
def process_message(self, peer, mailfrom, rcpttos, raw_message): logger.info('Incoming message received from %s', mailfrom) if not len(rcpttos): logger.info('Incoming email had no recipients. Ignoring.') return STATUS[550] if len(raw_message) > self.max_message_length: logger.info('Inbound email message was too long: %d', len(raw_message)) return STATUS[552] try: group_id = email_to_group_id(rcpttos[0]) except Exception: logger.info('%r is not a valid email address', rcpttos) return STATUS[550] message = email.message_from_string(raw_message) payload = None if message.is_multipart(): for msg in message.walk(): if msg.get_content_type() == 'text/plain': payload = msg.get_payload() break if payload is None: # No text/plain part, bailing return STATUS[200] else: payload = message.get_payload() payload = EmailReplyParser.parse_reply(payload).strip() if not payload: # If there's no body, we don't need to go any further return STATUS[200] process_inbound_email.delay(mailfrom, group_id, payload) return STATUS[200]