pengembangan-web-mp-pd.com

Django 1.8 mengirim surat menggunakan SMTP gmail

Saya mencoba mengirim email menggunakan smtp.gmail.com di Django 1.8

settings.py saya mengandung:

EMAIL_BACKEND = 'Django_smtp_ssl.SSLEmailBackend'
EMAIL_Host = 'smtp.gmail.com'
EMAIL_PORT = 465
EMAIL_Host_USER = 'sarath4coding'
EMAIL_Host_PASSWORD = '*********'
DEFAULT_EMAIL_FROM = '[email protected]'

from Django.core import mail
mail.send_mail('subject','message','[email protected]',['[email protected]'])

Tapi ada kesalahan ini 

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/Django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/Django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/Django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/home/manager/dj1.8/local/lib/python2.7/site-packages/Django_smtp_ssl.py", line 14, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuze\n5.7.14 2FDKQt2Dlo2vqFIvbr6DnBItwWvh9DChPwbeTZO66N91gzmiA437Vqs80cZ9-8u13vxq5a\n5.7.14 bVahzO_BQcZ53yKbJ-YbAlmFE1XIK7MfH97O0wI1lvzpTG_WAHuTIBF0HD1GA2icUoUemt\n5.7.14 ErZn4qb942aAIMG103FnrzLp4txXTbXC-wGLpaz5yvnUN5thahvv3-RiIVW8F1QddZKZlg\n5.7.14 qQKpqWw56zr1AcO2s_oaBEt556fQ> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 kx14sm6579665pab.0 - gsmtp')

Saya mencoba semua yang dikatakan dokumen dan mengikuti banyak solusi yang disarankan.

like https://accounts.google.com/DisplayUnlockCaptcha , mengaktifkan aplikasi keamanan rendah dll.

tapi saya masih punya kesalahan

Adakah yang tahu, cara mengkonfigurasi Django 1.8 dengan benar untuk mengirim email menggunakan Gmail.

25
Sarath Babu

untuk saya di settings.py:

EMAIL_USE_TLS = True
EMAIL_Host = 'smtp.gmail.com'
EMAIL_Host_USER = '[email protected]'
EMAIL_Host_PASSWORD = 'test'
EMAIL_PORT = 587

dan views.py:

from Django.core.mail import EmailMessage

email = EmailMessage('title', 'body', to=[email])
email.send()

dan: https://accounts.google.com/DisplayUnlockCaptcha

37
Alex Karahanidi

Ingatlah untuk:

Buka pengaturan Akun Google Anda, temukan Keamanan -> Izin akun -> Akses untuk aplikasi yang kurang aman, aktifkan opsi ini.

Tentang opsi ini: https://support.google.com/accounts/answer/6010255

17
edilio

Saya menguji ini dan bekerja dengan sempurna di Django 1.8:
pertama Anda harus memeriksa tautan ini , disediakan oleh google yang telah Anda lakukan :)
.__ perhatikan bahwa untuk beberapa alasan aneh yang saya tidak tahu, Anda harus kode seperti ini di view.py or Shell

import Django
from Django.conf import settings
from Django.core.mail import send_mail

send_mail('Subject here', 'Here is the message.', settings.EMAIL_Host_USER,
         ['[email protected]'], fail_silently=False)

juga ini adalah pengaturan saya dalam file setting.py

EMAIL_USE_TLS = True
EMAIL_BACKEND = 'Django.core.mail.backends.smtp.EmailBackend'
EMAIL_Host = 'smtp.gmail.com'
EMAIL_Host_PASSWORD = 'xxxx' #my gmail password
EMAIL_Host_USER = '[email protected]' #my gmail username
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_Host_USER
11
Iman Mirzadeh

ganti dalam file settings.py Anda:

EMAIL_BACKEND = 'Django_smtp_ssl.SSLEmailBackend'

oleh

EMAIL_BACKEND = 'Django.core.mail.backends.smtp.EmailBackend'

7
Ajay Gupta

Di settings.py Ubah ini

EMAIL_Host='imap.gmail.com'
EMAIL_PORT = 587
EMAIL_Host_USER = '[email protected]'
EMAIL_Host_PASSWORD ='**********'
EMAIL_USE_SSL=False
EMAIL_USE_TLS= True
5
Abhishek Yadav

Ini bekerja untuk saya:

settings.py

EMAIL_BACKEND = 'Django_smtp_ssl.SSLEmailBackend'
EMAIL_Host = 'smtp.gmail.com'
EMAIL_Host_PASSWORD = 'test'
EMAIL_Host_USER = '[email protected]'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

Buka Captcha: https://accounts.google.com/DisplayUnlockCaptcha

views.py

email = EmailMessage(
    'subject_message',
    'content_message',
    'sender smtp gmail' +'<[email protected]>',
    ['[email protected]'],
    headers = {'Reply-To': '[email protected]' }
)
email.send()
1
ordenador.cl

Saya menggunakan ini untuk Django 1.11

Di settings.py

EMAIL_USE_TLS = True
EMAIL_BACKEND = 'Django.core.mail.backends.smtp.EmailBackend'
EMAIL_Host = 'smtp.gmail.com'
EMAIL_Host_PASSWORD = 'sender' #sender mail password
EMAIL_Host_USER = '[email protected]' #sender mail username
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_Host_USER

Di view.py

send_mail('mail subject', 'body content',settings.EMAIL_Host_USER,
                      ['[email protected]'], fail_silently=False)

dan goto https://myaccount.google.com/u/0/security?hl=id untuk mengaktifkan akses aplikasi yang kurang aman

0
Parthi.N