是否可以使用实用程序 django sendmail 执行以下操作?
>>> import os
>>> from django.core.mail import send_mail
>>> os.environ['EMAIL_BACKEND'] = 'django.core.mail.backends.smtp.EmailBackend'
>>> os.environ['EMAIL_HOST'] = 'smtp.sendgrid.net'
... etc.
>>> send_mail(
... 'Subject here',
... 'Here is the message.',
... 'from@example.com',
... ['to@example.com'],
... fail_silently=False,
... )
django.core.exceptions.ImproperlyConfigured:请求设置 EMAIL_BACKEND,但未配置设置。您必须在访问设置之前定义环境变量 DJANGO_SETTINGS_MODULE 或调用 settings.configure()。
如果是这样,我该怎么做?