[英]How to send an email to currently logged in user Django
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.我目前正在尝试设置一个视图,以便当用户访问路径 /clip 时,它会向用户的收件箱发送一封电子邮件。
Eg.例如。 I visit path, email turns up in my inbox.
我访问路径,电子邮件出现在我的收件箱中。
I am using this:我正在使用这个:
from django.core.mail import send_mail
def clippy(request):
current_user = request.user
subject = "test"
message = "testing"
recipient_list = [current_user.email]
send_mail(subject, message, recipient_list)
I'm using 3.0.4 and get this error when I visit the path:我正在使用 3.0.4 并在访问路径时收到此错误:
send_mail() missing 1 required positional argument: 'recipient_list'
Can anyone help?任何人都可以帮忙吗? Thanks
谢谢
EDIT : I have used the answer by reza heydari and it fixes this issue, now I get the following:编辑:我使用了 reza heydari 的答案,它解决了这个问题,现在我得到以下信息:
TypeError at /clip/
send_mail() missing 1 required positional argument: 'from_email'
@login_required()
def clippyemail(request):
current_user = request.user
subject = 'Clippy here',
message = 'Hi! I am clippy! You resserected me somehow so thanks!',
recipient_list = [current_user.email, ]
send_mail(subject, message, recipient_list=recipient_list)
is there any way I can set it up so it just sends the email using the SMTP settings in settings.py?有什么方法可以设置它,让它只使用 settings.py 中的 SMTP 设置发送电子邮件?
The 3rd arg of send_mail
is from_email
based on docs Change your code like that: send_mail
的第三个参数是基于 文档的from_email
像这样更改代码:
send_mail(subject, message, from_email="example@email.com", recipient_list=recipient_list)
And also add并且还添加
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
For your local to recieve email in terminal让您的本地人在终端接收电子邮件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.