Итак, я использую heroku и sendgrid и думаю, что мои настройки settings.py настроены правильно:
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']
Я отправляю электронную почту, используя send_mail следующим образом (используя получатель pre_save, чтобы проверить, изменился ли атрибут... также «[email protected]» заменяется моим фактическим адресом электронной почты):
@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,'[email protected]',[u.email],fail_silently=False)
Журналы показывают, что оно отправляется ... но я не получаю его в свой почтовый ящик, и в разделе учетной записи надстройки sendgrid не говорится, что я отправил электронные письма. У кого-нибудь была эта проблема раньше?
Редактировать:
Вот мой импорт settings.py
import os
import sys
И файл моих моделей (где происходит send_mail):
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
А вот лог вызова send_mail:
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: [email protected]
2012-05-28T21:16:49+00:00 app[web.1]: To: [email protected]
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
import os
в файле settings.py? - person Swift   schedule 29.05.2012