persona
persona

Reputation: 108

Confirming whether an email exists or not

There are similar questions and I have already basically checked all of them. My question is when I try to clarify whether an e-mail really exists or not(such as [email protected], I cannot clarify the same with my company email.

The package I have used is py3-validate-email. Can anyone point me in the right direction for what I should do as the next step?

I know that this tool checks for the regex as well, I have copied the code to receive any opinion.

from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader 
from django.http import Http404

from django.core.mail import send_mail
from django.conf import settings
import re

from validate_email import validate_email

def validate_email_address(email_address):

   return re.search(r"^[A-Za-z0-9_!#$%&'*+\/=?`{|}~^.-]+@[A-Za-z0-9.-]+$", email_address)

def contact_func(request, ):
    template = loader.get_template("contact_page/contact_page.html")
    context = {
        "contact":"contact_us",
        }

    if request.method == 'POST':
        message = request.POST['message']
        email = request.POST['email']
        name = request.POST['name']


        if not validate_email_address(email):
            return HttpResponse("Invalid email address")

        is_valid = validate_email(
        email_address= email, 
        check_format=True,
        check_blacklist=True,
        check_dns=True,
        dns_timeout=10,
        check_smtp=True,
        smtp_timeout=10,
        smtp_helo_host='smtp.gmail.com',
        smtp_from_address='my_mail.com',
        smtp_skip_tls=False,
        smtp_tls_context=None,
        smtp_debug=False,
    )

        if not is_valid:
            return HttpResponse("Invalid email address")




        send_mail(
            name, #title
            message + '\nsend by ' + email,
            request.POST['email'],
            ['my_mail.com'], #receiver email
            fail_silently=False, 
        )

    return HttpResponse(template.render(context, request))


    


Upvotes: 0

Views: 108

Answers (0)

Related Questions