TypeError:send_mail()只需3个参数(给定1个)

时间:2016-05-19 17:03:28

标签: python django multithreading email

我的Django项目中有一个应用程序,如果温度高于最高温度,则在运行服务器时异步发送电子邮件。实际上作为一个开始,我只发送给一个接收者,我将从foo函数收到的温度与一个恒定的温度进行比较。

但它既没有异步发送电子邮件,也没有当我访问此应用程序时,它返回错误说:

  

TypeError:send_mail()只需3个参数(给定1个)

mail / views.py

from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from threading import Thread
from cap import foo 

class EmailThread(Thread):
    def __init__(self, subject, content, from_email):
        self.subject = request.POST.get('subject', 'subject')
        self.content = request.POST.get('content', 'attention ! la temperature a depasse le maximum ')
        self.from_email = request.POST.get('from_email', '*****@gmail.com')
        Thread.__init__(self)

    def run(self):

        if subject and content and from_email:
            try:
                send_mail(subject, content, from_email, [ '******@gmail.com' ])
                return HttpResponse('templates/mail.html')
            except BadHeaderError:
                return HttpResponse('Invalid header found.')
            return HttpResponseRedirect('mail')
        else:

            return HttpResponse('Make sure all fields are entered and valid.')
def send_mail(subject, content, recipient):
    x = foo()
    if x >= 12 :
        EmailThread(subject, content, recipient).start()

1 个答案:

答案 0 :(得分:0)

正如上面的评论所说,您正在重新定义send_mail。当我从插件电子邮件发送功能切换到本机django时,我陷入了这个混乱,忘了我的原始功能叫做send_mail。