Skip to content

Inbound email receiver returns AnymailInvalidAddress error on Heroku + Python 2.7 #98

@rnevius

Description

@rnevius

Project Info:

  • Anymail 2.0
  • ESP: Mailgun
  • Django 1.8
  • Python 2.7.14
  • Heroku host

Stack Trace:

Internal Server Error: /admin/messages/webhooks/mailgun/inbound/
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/webhooks/base.py", line 109, in dispatch
    return super(AnymailBaseWebhookView, self).dispatch(request, *args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/webhooks/base.py", line 126, in post
    self.signal.send(sender=self.__class__, event=event, esp_name=esp_name)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 201, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/app/./urban_site/messages/views.py", line 84, in handle_inbound
    [agent.email]
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/base.py", line 90, in send_messages
    sent = self._send(message)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/base_requests.py", line 58, in _send
    return super(AnymailRequestsBackend, self)._send(message)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/base.py", line 119, in _send
    payload = self.build_message_payload(message, self.send_defaults)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/mailgun.py", line 30, in build_message_payload
    return MailgunPayload(message, defaults, self)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/mailgun.py", line 71, in __init__
    super(MailgunPayload, self).__init__(message, defaults, backend, auth=auth, *args, **kwargs)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/base_requests.py", line 119, in __init__
    super(RequestsPayload, self).__init__(message, defaults, backend)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/backends/base.py", line 268, in __init__
    value = converter(value)
  File "/app/.heroku/python/lib/python2.7/site-packages/anymail/utils.py", line 158, in parse_address_list
    raise AnymailInvalidAddress(errmsg)
AnymailInvalidAddress: Invalid email address '' parsed from ''.

Relevant Code:

@receiver(inbound)
def handle_inbound(sender, event, esp_name, **kwargs):
    message = event.message
    from_email = message.from_email.addr_spec

I suspect this is an issue with parsing addr_spec, as doing print(message.from_email) returns a valid email in the form: First Last <firstlast@outlook.com> (also occurs from Gmail addresses). This issue doesn't occur when using ngrok locally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions