我想使用两封电子邮件,一封用于验证电子邮件,另一封用于发送正常的信息电子邮件。我可以使用以下代码发送电子邮件以进行验证,并且我想将我的另一封电子邮件用于第二个目的。
视图.py
current_site = get_current_site(request)
subject = 'Welcome to MySite! Confirm Your email.'
htmly = get_template('account_activation_email.html')
d = { 'user': user, 'domain':current_site.domain, 'uemail':urlsafe_base64_encode(force_bytes(user.email)), 'uid':urlsafe_base64_encode(force_bytes(user.pk)), 'token': account_activation_token.make_token(user)}
text_content = ""
html_content = htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, '', [user.email])
msg.attach_alternative(html_content, "text/html")
try:
msg.send()
except BadHeaderError:
print("Error while sending email!")
user.save()
并在设置中:
EMAIL_USE_TLS = True
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = verify@mysite.com
EMAIL_HOST_PASSWORD = 'randompass'
EMAIL_PORT = config('EMAIL_PORT')
DEFAULT_FROM_EMAIL = 'MySte Verification <verify@mysite.com>'
请帮忙!!!