添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
聪明伶俐的煎鸡蛋  ·  Java UUID ...·  11 月前    · 
果断的汉堡包  ·  java - ...·  1 年前    · 
追风的机器人  ·  Unicode character , ...·  1 年前    · 
悲伤的数据线  ·  html - WebM / MP4 ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am writing django application and trying to send email using it I have "Access to low security app" in gmail enabled and django setting are given below which I think are right. but I am still getting error as mentioned it title. I dont know the problem but I know I am not getting logged in to send email. Edit 1: I have made two changes first in settings.py and second in views.py in views.py I replaced email entered by user to mine(syedfaizan824@gmail.com) and settings.py DEFAULT_EMAIL_FROM is changed form testing@example.com to syedfaizan824@gmail.com

searched on internet and find out that gmail does not allow low security app to login by default but I turned it off in setting of gmail. find out that my email backend was wrong so made it right. fail silently is False.

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = 'syedfaizan824@gmail.com'
EMAIL_HOST_USER = 'syedfaizan824@gmail.com'
EMAIL_HOST_PASSWORD = '******'

views.py

def post(self, request, *args, **kwargs):
    form = contact(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        email = form.cleaned_data['email']
        phone = form.cleaned_data['phone']
        organization = form.cleaned_data['organization']
        message = form.cleaned_data['message']
        ref_code = form.cleaned_data['ref_code']
        plan = form.cleaned_data['plan']
        message = message + ref_code 
        send_mail(
            'from website' + name + " " + organization,
             message,
            'syedfaizan824@gmail.com',
            ['syedfaizan824@gmail.com'],
            fail_silently=False,
        print("sent")
    else:
        #print('something is wrong with forms!')
    return render(request, self.template_name, self.context)

Error message is ConnectionRefusedError WinError[10061]. and statement of error is : No connection could be made because the target machine actively refused it. which means I am not getting logged in.

Are 'testing@example.com' and 'syedfaizan824@gmail.com' on the same Gmail account? Are these linked somehow? – Matthew Gaiser Sep 11, 2019 at 17:15 No I think that when someone sees website and tries to contact he provide some email if the email field is not provided that from email is used from DEFAULT_FROM_EMAIL although I have tried setting it to syedfaizan824@gmail.com which is my account and I am trying to send email from and to this account with entered information. – Faizan Syed Sep 11, 2019 at 17:39 I have edited the question and views.py and settings.py according to your comment Matthew Gaiser. – Faizan Syed Sep 11, 2019 at 17:43 Besides that, your settings.py looks exactly like mine. ``` EMAIL_HOST = 'smtp.gmail.com' EMAIL_USE_TLS = True EMAIL_PORT = 587 EMAIL_HOST_USER = 'myemail@gmail.com' EMAIL_HOST_PASSWORD = '********' ``` – Matthew Gaiser Sep 11, 2019 at 18:03 Does it work when you try the console email backend? EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' – Matthew Gaiser Sep 11, 2019 at 18:04

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.