内容正在载入中,请稍后……
公告
搜索
统计
其他
13 Nov.2011

在Django中通过Gmail发送电子邮件 夜晚

作者: 我就是个世界   分类:技术&学习 » Django   出处:MangoOrange            | |
While I was learning how to use django-registration app, I discover in the tutorial that I need to know how to send an email for the user to activate the registration.
我找到了这个指南,教我学习如何去使用 django-registration app,如何为用户发送电子邮件,以激活注册。
Thanks to folk at the Django chatroom, they advice me to google 'django gmail' and I discover a post at nathanostgard.com that show roughly how to do it. Here I'm going to extend a little on how to test it using shell.

1. Create a project, 创建一个项目
django-admin.py startproject gmail

2. Edit settings.py with code below: 在settings.py 中添加如下代码

    EMAIL_USE_TLS = True
    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_HOST_USER = 'youremail@gmail.com'
    EMAIL_HOST_PASSWORD = 'yourpassword'
    EMAIL_PORT = 587

3. Run interactive mode, 运行交互模式
python manage.py shell

4. Import the EmailMessage module, 导入EmailMessage模块
    
from django.core.mail import EmailMessage

5. Send the email, 发送邮件测试

    email = EmailMessage('Subject', 'Body', t=['mickeyckm@mangoorange.com'])
    email.save()


Hope it help someone :) Reference here and here.
希望能帮助别人, :)  参考资料: here and here.
分享到QQ空间
发表评论
  昵称 [注册]
  密码 (游客无需密码)
  网址
  电邮
OpenID登入 权限选项 表情