ngoctranfire
ngoctranfire

Reputation: 793

Weird Django TypeError: send_mail() takes at least 4 arguments (4 given)

I am trying to actually test sending an email using mailtrap.io, and I set up the email server as directed, however, when I try to do the following:

form = InterestedForm(request.POST)
if form.is_valid():
    name = form.cleaned_data['name']
    email = form.cleaned_data['email']
    subject = "Index form: Interested in Ucodon"
    message = 'Name: ' + name + '\n' + 'Email: ' + email
    recipients=['[email protected]']
    send_mail(subject, message, recipients, fail_silently=False)
    thanks = True

I get the following error:

TypeError: send_mail() takes at least 4 arguments (4 given)

I have even tried the following:

send_mail(subject=subject, message=message, recipients=recipients, fail_silently=False)

Also, I have defined EMAIL_HOST_USER. I am currently using EMAIL_HOST='mailtrap.io'.

Upvotes: 4

Views: 4221

Answers (2)

alecxe
alecxe

Reputation: 473943

According to the documentation:

send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, connection=None, html_message=None)¶

You are missing from_email argument.

Either set it, or pass None - in this case Django would use DEFAULT_FROM_EMAIL setting value:

send_mail(subject, message, None, recipients, fail_silently=False)

Upvotes: 5

jax
jax

Reputation: 840

Subject, message, from_email and recipient are required. I do not see you have provided the from_email. You can refer to https://docs.djangoproject.com/en/dev/topics/email/#send-mail for more info.

Upvotes: 0

Related Questions