Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Godaddy email via Django using python

I have these settings

EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 465
EMAIL_USE_TLS = True
SMTP_SSL = True

Speaking to Godaddy I have found out these are the ports and settings

smtpout.secureserver.net
ssl
465

587
TLS ON

3535
TLS ON

25
TLS ON

80
TLS ON
or
TLS OFF

I have tried all the combinations. If I set TLS to True I am getting

STARTTLS extension not supported by the server.

If I set to 465 I am getting

Connetion Closed

If I set other combinations like

EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'
EMAIL_PORT = 25
EMAIL_USE_TLS = False

Invalid Address

For verification, I used Google Mail settings to test if the email sending via python works, and it is working.

Now I want to switch to GoDaddy and I know for the email we use TLS to log in even for POP3 download and it is working, so I am not sure why python / Django option is not working. Can you please help?

I have called Godaddy, they cannot help because it is a software issue - all their settings and ports are working, so I have no one to ask.

like image 485
Radek Avatar asked Nov 25 '17 05:11

Radek


People also ask

How do I send multiple emails in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.


2 Answers

This worked for me with my GoDaddy email. Since GoDaddy sets up your email in Office365, you can use smtp.office365.com.

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = '[email protected]'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = 'myPassword'
EMAIL_PORT = 587
EMAIL_USE_SSL = False
EMAIL_USE_TLS = True

method in views.py that handles sending email. The email variable is from a user form.

from django.conf import settings
from django.core.mail import EmailMessage
def send_email(subject, body, email):
    try:
        email_msg = EmailMessage(subject, body, settings.EMAIL_HOST_USER, [settings.EMAIL_HOST_USER], reply_to=[email])
        email_msg.send()
        return "Message sent :)"
    except:
        return "Message failed, try again later :("
like image 56
bvmcode Avatar answered Sep 29 '22 12:09

bvmcode


I found this code worked for me.. Hope this will be useful to somebody.
I was using SMTP godaddy webmail..you can put this code into your django setting file.
Since you cannot set Both SSL and TSL together... if you do so you get the error something as, At one time either SSL or TSL can be true....

setting.py

# Emailing details
EMAIL_HOST = 'md-97.webhostbox.net'
EMAIL_HOST_USER = 'mailer@yourdomain'
EMAIL_HOST_PASSWORD = 'your login password'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
like image 31
Priyanka Avatar answered Sep 29 '22 10:09

Priyanka