0

I'm trying to send an actual email to myself from my website using send_mail. I had used localhost and the following cmd command,

python -m smtpd -n -c DebuggingServer localhost:1025 

in order to test it. It intercepts with no problem, but I don't see anything in my inbox.

Here is the settings.py file:

EMAIL_HOST = '178.67.220.242' # My current ip address 
EMAIL_PORT = '587' # Port of the email host  
EMAIL_HOST_USER = 'b....a1@gmail.com' # Here is my actual email  
EMAIL_HOST_PASSWORD = '.....' # Here is my actual password from my email login   
EMAIL_USE_TLS = True  
EMAIL_USE_SSL = False

Here is the views.py file:

from django.shortcuts import render 
from django.core.mail import send_mail 
from .forms import ContactForm  

def contact(request):     
    form = ContactForm     
    if request.method == 'POST':          
        message_name = request.POST.get('name')          
        message_email = request.POST.get('email')          
        message = request.POST.get('message') 
        send_mail(message_name, message, message_email, ['b....a1@gmail.com'])     
    return render(request, 'contact.html', {'form': form})

Here is the error:

Traceback (most recent call last):
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\1\PycharmProjects\StasProject\sales_project\contact\views.py", line 15, in contact
    send_mail(message_name, message, message_email, ['badabuska1@gmail.com'])
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\mail\__init__.py", line 61, in send_mail
    return mail.send()
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\mail\message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\mail\backends\smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\mail\backends\smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "C:\Users\1\AppData\Local\Programs\Python\Python38\lib\smtplib.py", line 258, in __init__
    raise SMTPConnectError(code, msg)

Exception Type: SMTPConnectError at /contact/
Exception Value: (421, b'Cannot connect to SMTP server 178.67.220.242 (178.67.220.242:587), connect error 10061')
Badabuska
  • 1
  • 2

1 Answers1

0

Why are you putting your IP as EMAIL_HOST, this shall be the IP of the email server which by Gmail from the settings which shall be 'smtp.gmail.com'

Mohamed ElKalioby
  • 1,908
  • 1
  • 12
  • 13