4

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=['test@gmail.com']
    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'.

ngoctranfire
  • 793
  • 9
  • 15

2 Answers2

5

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)
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I thought that if you have a EMAIL_HOST_USER defined in ur settings, it will default to that as being the from_email? – ngoctranfire Aug 14 '14 at 03:57
  • @ngoctranfire nope, `from_email` should be passed in. `EMAIL_HOST_USER` would be used as `auth_user` argument value unless provided. – alecxe Aug 14 '14 at 03:59
  • @ngoctranfire also see [this example](https://docs.djangoproject.com/en/dev/topics/email/#quick-example). – alecxe Aug 14 '14 at 04:01
  • Wow thanks! It worked, however, I seem to be getting another error that says the following: SMTPAuthenticationError: (534, '5.7.14... etc....'), with a link in there to my gmail, but this is extremely weird because none of the emails I have anywhere (from_email, or even the recipientlist) has any gmail information associated with it. – ngoctranfire Aug 14 '14 at 04:04
  • @ngoctranfire btw, you can also set `DEFAULT_FROM_EMAIL` setting and it would be used in case you pass `None` inside the `from_email`. I've updated the answer and included that. – alecxe Aug 14 '14 at 04:08
0

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.

jax
  • 840
  • 2
  • 17
  • 35