Heroku, Django, and Sendgrid - emails not sending?

纵饮孤独 提交于 2021-02-19 08:48:08

问题


So I'm using heroku and sendgrid and think I have my settings.py configured correctly:

EMAIL_HOST_USER = os.environ['SENDGRID_USERNAME']
EMAIL_HOST= 'smtp.sendgrid.net'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PASSWORD = os.environ['SENDGRID_PASSWORD']

I'm sending email using send_mail like this (using pre_save receiver to check if attribute has changed... also 'myemail@gmail.com' is replaced with my actual email):

@receiver(pre_save,sender=LotteryEntry)
def send_email_if_invited(sender,instance,**kwargs):
    try:
        obj = LotteryEntry.objects.get(pk=instance.pk)
    except LotteryEntry.DoesNotExist:
        #could send email here telling them when they should know
        pass
    else:
        if not obj.invited == instance.invited:
            l = Dinner.objects.get(id=instance.dinner.id)
            u = User.objects.get(id=instance.user.id)
            message = "You have been chosen to attend %s! Here is the description of the event: %s. We will see you there!" % (l.title,l.description)
            send_mail('You have been invited!',message,'myemail@gmail.com',[u.email],fail_silently=False)

The logs show that it is being sent.. but I'm not receiving it in my inbox nor does the sendgrid addon account section say I have sent emails. Anyone have this problem before?

Edit:

Here are my imports of settings.py

import os
import sys

And my models file (where send_mail happens):

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import *
from django.dispatch import receiver
from django.core.mail import send_mail

And here is a log of the send_mail call:

Content-Type: text/plain; charset="utf-8"
2012-05-28T21:16:49+00:00 app[web.1]: MIME-Version: 1.0
2012-05-28T21:16:49+00:00 app[web.1]: Content-Transfer-Encoding: quoted-printable
2012-05-28T21:16:49+00:00 app[web.1]: Subject: You have been invited!
2012-05-28T21:16:49+00:00 app[web.1]: From: msencenb@stanford.edu
2012-05-28T21:16:49+00:00 app[web.1]: To: msencenb@stanford.edu
2012-05-28T21:16:49+00:00 app[web.1]: Date: Mon, 28 May 2012 21:16:49 -0000
2012-05-28T21:16:49+00:00 app[web.1]: Message-ID: <20120528211649.1.49209@2a33c2a2-9b5e-4da9-994c-15de8157702e>
2012-05-28T21:16:49+00:00 app[web.1]: 
2012-05-28T21:16:49+00:00 app[web.1]: You have been chosen to attend Web Development Pt. 1! Here is the descripti=
2012-05-28T21:16:49+00:00 app[web.1]: on of the event: Knight Management Center, 5/23/12 12:30 to 2 PM. We will s=
2012-05-28T21:16:49+00:00 app[web.1]: ee you there!
2012-05-28T21:16:49+00:00 app[web.1]: -------------------------------------------------------------------------------
2012-05-28T21:16:49+00:00 app[web.1]: [28/May/2012 16:16:49] "POST /admin/dinners/lotteryentry/1/ HTTP/1.1" 302 0
2012-05-28T21:16:49+00:00 heroku[router]: POST morning-frost-2949.herokuapp.com/admin/dinners/lotteryentry/1/ dyno=web.1 queue=0 wait=0ms service=107ms status=302 bytes=0

来源:https://stackoverflow.com/questions/10790603/heroku-django-and-sendgrid-emails-not-sending

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!