我知道这是有效的,因为我有django-registrations应用程序发送激活邮件。但是我没有运气为另一个应用程序重新创建这个功能。在views.py中,在add_article函数中,我执行芹菜任务send_publishhed_article .delay(request.user.email, subject, body),这在本地工作。但是当我部署到Heroku时,当我将is_publish设置为true时,没有发送任何电子邮件。没有错误生成,所以我不确定从哪里开始查找
Heroku日志显示发送邮件失败的原因如下:POST: 2013-04-30T20:57:55.650246+00:00 Heroku [router]: at=info method=POST path=/story/add/article host= secu-brook-2084.herokuapp.com fwd="108.167.16.106" dyno=web。1连接=0ms服务=265ms状态=302字节=5
tasks.py
from django.core.mail import send_mail
from celery import task
from apps.profiles.models import Client
@task(name='send-email')
def send_published_article(sender, subject, body):
for client in Client.objects.all():
recipient = client.email
send_mail(subject, body, sender, [recipient], fail_silently=False)
views.py
import os
import redis
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext
from models import Article
from forms import ArticleForm
from story.tasks import send_published_article
@login_required
def add_article(request):
if request.method == 'POST':
form = ArticleForm(request.POST, request.FILES or None)
if form.is_valid():
article = form.save(commit=False)
article.author = request.user
article.save()
msg = "Article saved successfully"
messages.success(request, msg, fail_silently=True)
if article.is_published:
subject = article.title
body = article.text
send_published_article.delay(request.user.email, subject, body)
msg = "Article saved and published successfully"
messages.success(request, msg, fail_silently=True)
return redirect(article)
else:
form = ArticleForm()
return render_to_response('story/article_form.html',
{ 'form': form },
context_instance=RequestContext(request))
我已经在我的settings。production中设置了如下设置:
EMAIL_BACKEND = 'django_ses.SESBackend'
DEFAULT_FROM_EMAIL = 'ME <my.email@email.com>'
如果你需要更多的信息,或者有一个关于测试的想法来帮助找到错误,请告诉我。
谢谢,
这个问题的解决方法如此简单,以至于我都想哭了。我没有在我的Heroku应用程序中启用celeryd和celerybeat dynos。打开它们,应用更改,然后,boom,电子邮件。