簡體   English   中英

Send_mail未發送到gmail ID的郵件。 [django的]

[英]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"

執行后,我可以看到該消息是從xxx@gmail.com發送到yyy@gmail.com的

發送郵件之前:

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

發送郵件后:

沒有。

您已在設置文件中添加了followring中間件

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

這不會將電子郵件發送到Gmail客戶端。 電子郵件正文將在您的應用程序運行所在的應用程序控制台上打印。 嘗試刪除此行

嘗試這個:

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()

我認為您的錯誤是因為您沒有添加我添加的特殊部件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM