我正在尝试让Django管理员向站点的用户发送电子邮件。但是,我无法将电子邮件发送到用户的电子邮件收件箱。似乎没有任何编译问题,但收件箱中什么也没有。到底出了什么问题?我也确保在Django中正确设置电子邮件。这是我的代码:
views.py
def sendUserEmails(request):
form = SendEmailForm(request.POST)
print("going here")
if form.is_valid():
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
users = form.cleaned_data['users']
for user in users:
send_mail(subject, message, from_email, user.email, fail_silently = True)
user_message = '{0} users emailed successfully!'.format(form.cleaned_data['users'].count())
messages.success(self.request, user_message)
return render(request, 'admin/send_email.html', {'form': form})
forms.py
class SendEmailForm(forms.Form):
subject = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Subject'}))
message = forms.CharField(widget=forms.Textarea)
users = forms.ModelMultipleChoiceField(label = "To", queryset = Account.objects.all(), widget = forms.SelectMultiple())
admin.py中的电子邮件功能
def send_email(self, request, queryset):
form = SendEmailForm(initial = {'users' : queryset})
return render(request, 'admin/send_email.html', {'form': form})
urls.py
path('admin/solutions/account/', views.sendUserEmails, name='email'),
我尝试调试没有成功。请帮忙。