简体   繁体   中英

Send_mail is not sending to mail to gmail id. [django]

setting.py

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

DEFAULT_FROM_EMAIL = 'xxxxx@gmail.com'
SERVER_EMAIL = 'xxxxx@gmail.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'papercrib09@gmail.com'
EMAIL_HOST_PASSWORD = 'XXXXX'

views.py

print "before sending the mail"
send_mail(email_subject, email_body, 'xxx@gmail.com',
[yyy@gmail.com], fail_silently=False)
print "after sending the mail"

After executing it I am able to see that message is sent from xxx@gmail.com to yyy@gmail.com

before sending the mail:

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Account confirmation
From: xxx@gmail.com
To: yyy@gmail.com
Date: Sat, 22 Aug 2015 18:22:13 -0000
Message-ID: <20150822182213.5748.80357@SymMacToolkit-CPWKWBL7DTY3>

Hey user, thanks for signing up. To activate your account, click this link within 48 hours http://127.0.0.1:8000/accounts/confirm/1900aac9e91300ef2b35fdcc8cdc16305b2e0c18

after sending the mail:

nothing.

You have added the followring middleware in your settings file

'django.core.mail.backends.console.EmailBackend'

This will not send email to the Gmail client. The email body will print on your application console, Where your application is running. Try removing this line

Try this:

from email.mime.multipart import MIMEMultipart
import smtplib  # Use of SMTP is to connect to a mail server and send a message

# Email Settings
LOG_MAILTO = 'mail@gmail.com'  # Account email address
LOG_PASS = 'password'  # Email's password
LOG_FROM = 'othermail@gmail.com'    # Email will be sent from this address
LOG_SUBJ = 'BlahBlah'  # Email subject
LOG_MSG = 'BlahBlah'  # Email content - the body

# Send email function
msg = MIMEMultipart()
msg['Subject'] = LOG_SUBJ  # Mail subject
msg['From'] = LOG_FROM  # Mail sender
msg['To'] = LOG_MAILTO  # The mail will be send to this address
msg.preamble = LOG_MSG  # Mail body
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(LOG_FROM, LOG_PASS)
server.sendmail(LOG_FROM, LOG_MAILTO, msg.as_string())
server.quit()

I think that your error is because you didn't add spesific parts that I have added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM