I am currently trying to set up a view so when the user visits the path /clip it will send an email to the user’s inbox.
Eg. I visit path, email turns up in my inbox.
I am using this:
JavaScript
x
9
1
from django.core.mail import send_mail
2
3
def clippy(request):
4
current_user = request.user
5
subject = "test"
6
message = "testing"
7
recipient_list = [current_user.email]
8
send_mail(subject, message, recipient_list)
9
I’m using 3.0.4 and get this error when I visit the path:
JavaScript
1
2
1
send_mail() missing 1 required positional argument: 'recipient_list'
2
Can anyone help? Thanks
EDIT: I have used the answer by reza heydari and it fixes this issue, now I get the following:
JavaScript
1
3
1
TypeError at /clip/
2
send_mail() missing 1 required positional argument: 'from_email'
3
JavaScript
1
8
1
@login_required()
2
def clippyemail(request):
3
current_user = request.user
4
subject = 'Clippy here',
5
message = 'Hi! I am clippy! You resserected me somehow so thanks!',
6
recipient_list = [current_user.email, ]
7
send_mail(subject, message, recipient_list=recipient_list)
8
is there any way I can set it up so it just sends the email using the SMTP settings in settings.py?
Advertisement
Answer
The 3rd arg of send_mail
is from_email
based on docs
Change your code like that:
JavaScript
1
2
1
send_mail(subject, message, from_email="example@email.com", recipient_list=recipient_list)
2
And also add
JavaScript
1
2
1
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
2
For your local to recieve email in terminal