我知道这有效,因为我有django-registrations app发送激活电子邮件。但我没有运气为另一个应用程序重新创建此功能。在views.py中,在add_article函数中,我执行celery任务send_published_article.delay(request.user.email,subject,body),这在本地工作。但是当我部署到Heroku时,当我将is_published设置为true时,不会发送任何电子邮件。没有生成错误,所以我不确定从哪里开始查找。
Heroku日志显示这是因为尝试通过电子邮件发送POST失败:2013-04-30T20:57:55.650246 + 00:00 heroku [router]:at = info method = POST path = / story / add / article host = secure -brook-2084.herokuapp.com fwd =“108.167.16.106”dyno = web.1 connect = 0ms service = 265ms status = 302 bytes = 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>'
如果您需要更多信息,或对测试有所了解以帮助查找错误,请与我们联系。
谢谢,
答案 0 :(得分:4)
这个问题的解决方案非常简单,这让我想哭。我的Heroku应用程序中没有启用celeryd和celerybeat dynos。转过身来,应用了变化,繁荣,电子邮件。