在我的settings.py中,我有以下这些值:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'user@gmail.com'
EMAIL_HOST_PASSWORD = 'pass'
EMAIL_USE_TLS = True
然后在我的视图中,我从模型中获取电子邮件地址,例如:
#models.py
class Profile(models.Model):
name = models.CharField(...)
email_address = models.EmailField()
假设在Profile
模型中,email_address
为sample@gmail.com
#views
def send_email(request,profile_id):
profile = Profile.objects.get(pk=profile_id)
email = profile.email_address
当我发送邮件时,
send_mail('subject', 'content', email, ['example1@example.com'])
当邮件已经发送时,发件人邮箱仍然是user@gmail.com。有人能教我如何覆盖这个电子邮件地址吗?谢谢。