【发布时间】:2021-07-19 13:28:10
【问题描述】:
我在为我的 django 项目设置电子邮件选项时遇到了一些问题。 我在后端使用邮局,但我似乎无法排队。
views.py:
from django.views.generic import TemplateView
from post_office import mail
class EmailView(TemplateView):
model = Customer
mail.send(
'a.sophiewirth@gmail.com', # List of email addresses also accepted
'your.generic.test.email@gmail.com',
subject='My email',
message='Hi there!',
html_message='Hi <strong>there</strong>!',
)
template_name = 'customers/send_email.html'
settings.py:
# using post office as the default email backend
EMAIL_BACKEND = 'post_office.EmailBackend'
POST_OFFICE = {
'DEFAULT_PRIORITY' : 'now'
}
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "your.generic.test.email@gmail.com"
EMAIL_PORT = 25 # default smtp port
EMAIL_HOST_PASSWORD = "password"
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'your.generic.test.email@gmail.com'
urls.py:
from django.conf.urls import patterns, include, url
from customers.views import CustomerList, CreateCustomerView, CustomerUpdateView, EmailView
from . import views
urlpatterns = patterns('',
url(r'^$', CustomerList.as_view(), name="customer-list"),
url(r'^create-customer$', CreateCustomerView.as_view(), name="create-customer"),
url(r'^customer-update/(?P<pk>\d+)$', CustomerUpdateView.as_view(), name="customer-update"),
url(r'^send-email$', EmailView.as_view(), name="send-email"),
)
send_email.html 到目前为止是很空的,它只包含一个段落来告诉您您发送了一封电子邮件。
谁能告诉我为什么什么都没有发送?另外,作为我要发送邮件的特定用户,我怎样才能让电子邮件的收件人进入视图?
非常感谢:)
【问题讨论】:
-
你用的是什么排队系统?
-
我目前没有使用除 django 和 postgres 之外的任何其他系统。我没有意识到我需要专门添加一个排队系统。我确实在我的机器上安装了 celery。对不起,我对整个后端的事情真的很陌生,所以我知道我遇到了一个巨大的菜鸟。
-
对某事感到陌生并没有错。给我几分钟来完成其他事情,我将发布我的 Celery 设置作为示例。那时可能已经有人回答了,但至少现在你知道你至少可以得到一个答案!
-
感谢您如此友善并帮助我! :)