paper crib
paper crib

Reputation: 11

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

setting.py

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

DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'XXXXX'

views.py

print "before sending the mail"
send_mail(email_subject, email_body, '[email protected]',
[[email protected]], fail_silently=False)
print "after sending the mail"

After executing it I am able to see that message is sent from [email protected] to [email protected]

before sending the mail:

MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Account confirmation
From: [email protected]
To: [email protected]
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.

Upvotes: 1

Views: 375

Answers (2)

Muhammad Shoaib
Muhammad Shoaib

Reputation: 372

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

Upvotes: 1

Mike
Mike

Reputation: 37

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 = '[email protected]'  # Account email address
LOG_PASS = 'password'  # Email's password
LOG_FROM = '[email protected]'    # 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.

Upvotes: 0

Related Questions