django-mailgun icon indicating copy to clipboard operation
django-mailgun copied to clipboard

MailgunAPIError: <Response [400]>

Open alzearafat opened this issue 8 years ago • 9 comments

Hi,

I just following your readme, but I keep getting this error :

Image of Yaktocat

This is my setting (I'm not sure, whether I should using secret key or public key, but both is error when I'm trying to send email) :

EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = 'key-06b1d48a5805393c825ceefa054bXXXX'
MAILGUN_SERVER_NAME = 'sandboxfa1f6fe021044f319c639f9da08eXXXX.mailgun.org'

My views.py :

def order_form(request):
    if request.method == "POST":
        form = OrderForm(request.POST, request.FILES)
        if form.is_valid():
            order = form.save(commit=False)
            order.tanggal_order = datetime.datetime.now()
            order.save()
            subject = "NEW ZEGUYO ORDER"
            to = [order.email, '[email protected]', '[email protected]']
            from_email = '[email protected]'
            ctx = {
                'nama': order.nama,
                'id_order': order.id,
            }
            message = get_template('email/order_email.html').render(Context(ctx))
            msg = EmailMessage(subject, message, to=to, from_email=from_email)
            msg.content_subtype = 'html'
            msg.send()
            return render(request, 'order_app/order_success.html')
    else:
        form = OrderForm()
    return render(request, 'order_app/order_form.html', {'form': form})

I'm using django 1.9.2, Python 2.7

Did I miss something here?

Thank you in advance for any help you can provide :)

Regards,

alzearafat avatar Feb 25 '16 03:02 alzearafat

I've got this error too when moving from staging to production. I'm guessing it has something to do with ALLOWED HOSTS but I have not been able to crack it as yet

RyanSCL avatar Mar 23 '16 10:03 RyanSCL

Apologies for leaving this hanging for so long. Life got in the way. Does anyone know if Mailgun changed their API?

FWIW, I'm not having these problems myself. I can't reproduce them. Not yet anyway.

pydanny avatar Mar 23 '16 15:03 pydanny

I received the same error message, it was due a typo in an e-mail template. MailGun raised a 400 which sent me on a wild goose hunt. In the example above, if there is something awry with the ctx, it may do the same.

RyanSCL avatar Mar 23 '16 15:03 RyanSCL

Hi,

I still cannot get this work... So I have to convert to gmail, unfortunately :(

Is there any solution for this?

Thank you

alzearafat avatar Mar 24 '16 04:03 alzearafat

You can see error details in your Mailgun Logs. I got 400 response because I haven't activated account.

ozren1983 avatar Apr 12 '16 11:04 ozren1983

This project is unsupported. Please use https://github.com/anymail/django-anymail instead.

pydanny avatar May 04 '16 01:05 pydanny

Got the same error

@alzearafat try below settings in mailgun

Security Settings For Outgoing Mail Certificate Verification Not Required

it works for me

ithinco avatar May 07 '16 01:05 ithinco

@ithinco

Hi,

Thank you, I will test it out!

Thanks ! :D

alzearafat avatar May 12 '16 06:05 alzearafat

I had the same problem. Changing Certificate verification to: Not Required fixed this, see image from Mailgun settings:

illagrenan avatar Jun 01 '16 15:06 illagrenan