所以我正在使用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接收器检查属性是否已更改...还'myemail@gmail.com'已替换为我的实际电子邮件):
@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)
日志显示它正在发送..但我没有收到它在我的收件箱中,也没有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: 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
答案 0 :(得分:0)