We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If the world seems cold to you, kindle fires to warm it.
Sending e-mails with Django
SMTP
网络 STMP 服务器的话,需要在 settings.py 中添加:
STMP
settings.py
EMAIL_HOST
localhost
EMAIL_PORT
EMAIL_HOST_USER
EMAIL_HOST_PASSWORD
EMAIL_USE_TLS
TLS
EMAIL_USE_SSL
SSL
EMAIL_HOST = 'smtp.163.com' EMAIL_HOST_USER = 'your_account' EMAIL_HOST_PASSWORD = 'your_password' EMAIL_PORT = 25 EMAIL_USE_TLS = True
python manage.py shell
>>> from django.core.mail import send_mail >>> send_mail('Django mail', 'Test!!!!', 'your_account@163.com', ['recipient@xxx.com'], fail_silently=False)
fail_silently
views.py
from django.core.mail import send_mail from .forms import EmailPostForm def post_share(request, post_id): # 通过id检索post内容 post = get_object_or_404(Post, id=post_id, status='published') sent = False if request.method == 'POST': # 表单已提交 form = EmailPostForm(request.POST) if form.is_valid(): # 表单字段合法 cd = form.cleaned_data post_url = request.build_absolute_uri(post.get_absolute_url()) subject = '{} ({}) recommends you reading "{}"'.format(cd['name'], cd['email'], post.title) message = 'Read "{}" at {}\n\n{}\'s comments: {}'.format(post.title, post_url, cd['name'], cd['comments']) send_mail(subject, message, 'your_account@163.com', [cd['to']]) sent = True else: form = EmailPostForm() return render(request, 'blog/post/share.html', {'post': post, 'form': form, 'sent': sent})
sent
True
False
html
blog/urls.py
URL pattern
urlpatterns = [ # ... url(r'^(?P<post_id>\d+)/share/$', views.post_share, name='post_share'), ]
The text was updated successfully, but these errors were encountered:
No branches or pull requests
0x01 Django
Sending e-mails with Django
SMTP
服务器或者 网络SMTP
服务器网络
STMP
服务器的话,需要在settings.py
中添加:EMAIL_HOST
:SMTP
服务器主机,默认localhost
EMAIL_PORT
:SMTP
接口,默认25EMAIL_HOST_USER
: 用户名EMAIL_HOST_PASSWORD
: 密码EMAIL_USE_TLS
: 是否用TLS
安全连接EMAIL_USE_SSL
: 是否用SSL
安全连接python manage.py shell
fail_silently
这个参数可以回显发送是否成功,成功返回 1,失败的话,返回异常views.py
中sent
,如果发送了则为True
,否则False
,这个参数会在之后的html
模板中出现blog/urls.py
中添加一个URL pattern
The text was updated successfully, but these errors were encountered: