django email用法

在settings里面设置

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_PORT = 25
EMAIL_HOST = 'smtp.163.com'
EMAIL_HOST_USER = 'abcd@163.com'
EMAIL_HOST_PASSWORD = '111111'

 

from django.core.mail import send_mail

from oldman.settings import EMAIL_HOST_USER

def send_email(Subject, message, to):
    send_mail(Subject, message, EMAIL_HOST_USER,
              [to], fail_silently=False)

 

   seed_t = time.time() - 99
        seed_r = random.randint(500, 1000)
        temp_pwd = generate_code(t=seed_t, r=seed_r)[0:10]
        try:
            user = User.objects.get(email=email)
            user.set_password(temp_pwd)
            user.save()
            send_email('重置密码', '请使用如下密码重新登录并重置密码.' + temp_pwd, email)

也可以直接写send_mail不包装。

posted on 2014-07-16 10:16  颓废的悠然  阅读(538)  评论(0编辑  收藏  举报

导航