I'm trying to use Django-Templated-Email (0.4.7) to send an e-mail, and I keep receiving the following error:

TypeError at /intake/basic/
send_templated_mail() takes at least 4 arguments (4 given)
Request Method: POST
Request URL:    http://127.0.0.1:8000/intake/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:    
send_templated_mail() takes at least 4 arguments (4 given)

Below is an excerpt of my code from views.py:

from templated_email import send_templated_mail

class IntakeFormView(CreateView):
"""
Creates intake form request
"""
model = Intake
form_class = IntakeForm
template_name = 'intake.html'
success_url = '/intake/sent/'

def form_valid(self, form):
    # Save form to database
    self.object = form.save()

    from_email = 'from@fakemail.com'
    recipient_list = ['get@fakemail.com']

    send_templated_mail(context=
        {'client': self.object.client, 
         'type': self.object.type,     
         'issue': self.object.issue},
    template_name='intake',
    to=['to@fakemail.com'],
    bcc=recipient_list,
    from_email=from_email)

    return HttpResponseRedirect(self.get_success_url())

Below is the intake.email template file:

{% block subject %}
CLIENT ALERT: {{type}}
{% endblock %}

{% block plain %}

{{client}} needs help re {{issue}}.

{% endblock %}

Thanks for the help!

有帮助吗?

解决方案

send_templated_email does not have to as a keyword argument. You need to use recipient_list:

send_templated_email(
    recipient_list = ['to@fakemail.com']
    # your other arguments
)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top