첨부 파일이있는 전자 메일을 보내려고합니다. IOError : [Errno 2] 해당 파일이나 디렉토리가 없습니다. 하지만 그것이 말하는 URL은 존재하지 않습니다. 음, 실제로 존재합니다. 양식은 파일을 업로드하고 Signature = ... & 만료 = ... & AWSAccessKeyId = 끝에 추가 된 파일을 다른 창에서 불러올 때 파일과 함께 업로드하는 FileField.url을 업로드합니다.Amazon SES, Celery Tasks에서 Django의 첨부 파일로 전자 메일 보내기
내 Django 앱은 Amazon-SES를 사용합니다. 나는 send_mail()와 미세을 전송했지만, 첨부 파일을 지원하지 않는 래퍼, 그래서 난 내 tasks.py이 전환 :
from django.core.mail.message import EmailMessage
from celery import task
import logging
from apps.profiles.models import Client
@task(name='send-email')
def send_published_article(sender, subject, body, attachment):
recipients = []
for client in Client.objects.all():
recipients.append(client.email)
email = EmailMessage(subject, body, sender, [recipients])
email.attach_file(attachment)
email.send()
그리고 (A form.save 내보기에이 전화)
다음from story.tasks import send_published_article
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()
if article.is_published:
subject = article.title
body = article.text
attachment = article.docfile.url
send_published_article.delay(request.user.email,
subject,
body,
attachment)
return redirect(article)
else:
form = ArticleForm()
return render_to_response('story/article_form.html',
{ 'form': form },
context_instance=RequestContext(request))
입니다 로그는 말 :
app/celeryd.1: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/mail/message.py", line 268, in attach_file
app/celeryd.1: content = open(path, 'rb').read()
app/celeryd.1: IOError: [Errno 2] No such file or directory:
모든
나는 이메일에 링크를 삽입하는 방법을 알고 있습니다. 파일을 다운로드하고 나중에 삭제해야하는 명령을 모르겠습니다. 어떤 제안? 나는 [이 SO 페이지] (http://stackoverflow.com/questions/908258/generating-file-to-download-with-django)를 읽었으며 cStringIO를 많이 보았습니다.이 유형의 작업을 처리 할 수 있습니까? –