发送邮件来自django不起作用

时间:2021-11-17 00:23:31

i am trying to send the mail in django. mail is going properly but mail is going by EMAIL_HOST_USER. Want to send the mail using from i.e. from some other email address.

我想在django发送邮件。邮件正常,但邮件是通过EMAIL_HOST_USER进行的。想要从其他电子邮件地址发送邮件。

settings.py

EMAIL_HOST ='smtp.gmail.com' 
EMAIL_PORT = 587
EMAIL_HOST_USER = 'you@everycrave.me' 
EMAIL_HOST_PASSWORD = '*********' 
EMAIL_USE_TLS = True

in view:

text="hi this is test mail"
send_mail('Codeville Signup', text.decode(), 'gaurav@everycrave.me', ['manish@everycrave.me', 'jagat@everycrave.me'], fail_silently=False)

i want to send the mail from "gaurav@everycrave.me" but mail is getting sent by "you@everycrave.me" How can i overcome this problem. And i dont want to change EMAIL_HOST_USER mail address. Guide me through this

我想发送邮件“gaurav@everycrave.me”,但邮件是通过“you@everycrave.me”发送的。我怎样才能克服这个问题。而且我不想更改EMAIL_HOST_USER邮件地址。引导我完成这个

1 个解决方案

#1


0  

You can refer EmailBackend for sending email through multiple SMTP in Django this question or

你可以参考EmailBackend在Django中通过多个SMTP发送电子邮件这个问题或

in your view you have to write this code, from where you are sending the email.

在您的视图中,您必须编写此代码,从您发送电子邮件的位置。

from django.core.mail import get_connection, send_mail
from django.core.mail.message import EmailMessage
#TODO: Insert clever settings mechanism
my_host = 'smtp.gmail.com'
my_port = 587
my_username = 'your email address'
my_password = 'password'
my_use_tls = True
connection = get_connection(host=my_host, 
                            port=my_port, 
                            username=my_username, 
                            password=my_password, 
                            user_tls=my_use_tls) 

EmailMessage('Test subject', 'test message', 'from_email', ['to'], connection = connection).send(fail_silently=False)

Check this.

#1


0  

You can refer EmailBackend for sending email through multiple SMTP in Django this question or

你可以参考EmailBackend在Django中通过多个SMTP发送电子邮件这个问题或

in your view you have to write this code, from where you are sending the email.

在您的视图中,您必须编写此代码,从您发送电子邮件的位置。

from django.core.mail import get_connection, send_mail
from django.core.mail.message import EmailMessage
#TODO: Insert clever settings mechanism
my_host = 'smtp.gmail.com'
my_port = 587
my_username = 'your email address'
my_password = 'password'
my_use_tls = True
connection = get_connection(host=my_host, 
                            port=my_port, 
                            username=my_username, 
                            password=my_password, 
                            user_tls=my_use_tls) 

EmailMessage('Test subject', 'test message', 'from_email', ['to'], connection = connection).send(fail_silently=False)

Check this.