how to setup hmail server with a django project - python

I am trying to setup open source hmailserver with a django project. I have set up the server according to documentation. But I dont know how to use it with django.
For gmail i was using this setting:
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = Email
EMAIL_HOST_PASSWORD = Password
DEFAULT_FROM_EMAIL = Email
SERVER_EMAIL = Email
I tried changing the settings like this, But didn't worked:
EMAIL_USE_TLS = True
EMAIL_HOST = 'something.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'info#something.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'info#something.com'
SERVER_EMAIL = 'info#something.com'
hmail credentials are:
My domain name: something.com
My account name: info#somthing.com
How to configure it with django?

Did you add EMAIL_BACKEND?
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = 'no-reply#*****'
EMAIL_HOST = 'smtp.gmail.com'
# Port for sending e-mail.
EMAIL_PORT = 25
# Optional SMTP authentication information for EMAIL_HOST.
EMAIL_HOST_USER = '*****'
EMAIL_HOST_PASSWORD = '*****'
EMAIL_USE_TLS = False

SERVER_EMAIL should be the name of the computer which hMailServer runs on (usually it's not the same as the domain name).

Related

SMTP email error after Google's removal of less secure app access

Error:
SMTPAuthenticationError at /accounts/signup/
(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials n1-20020a05620a294100b006a6b6638a59sm3664075qkp.53 - gsmtp')
Before the update, the email sender works. Now after the update the email sender has a STMP authentication error.
How can I fix this error?
Code:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'tonoabot.noreply#gmail.com'
EMAIL_HOST_PASSWORD = os.environ['mailbotPass']
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
You should look into generating an app password. The password generated can then be used in the place of the the actual password for that account.
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'tonoabot.noreply#gmail.com'
EMAIL_HOST_PASSWORD = os.environ['appsPassword']
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

Sending mail though django

In my project, I tried to allow users to change and reset password. But can't figure out why this mail configuration isn't working. Actually, it doesn't send mail to the user. But showing e-mail has been sent on API.
Here is my code:
settings.py
REST_SESSION_LOGIN = True
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'username'
ACCOUNT_EMAIL_VERIFICATION = 'optional'
#mail config
EMAIL_HOST = 'smtp.gmail.net'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'mygmail#gmail.com'
EMAIL_HOST_PASSWORD = '************' #gmail app password
EMAIL_USE_TLS = True
urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('authentication/', include('dj_rest_auth.urls')),
path('authentication/registration/', include('dj_rest_auth.registration.urls')),
path('api/', include('articles.api.urls')),
re_path(r'^authentication/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(), name='password_reset_confirm')
]
And in terminal at from it shows webmaster#localhost. But why it isn't showing EMAIL_HOST_USER e-mail.
Subject: Password reset on example.com
From: webmaster#localhost
To: gicof53256#tdcryo.com
Date: Sun, 29 Nov 2020 08:14:16
When you have mentioned EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' this will mock the email, but not actually send it. To actually send it, replace it with the below settings.
Also, it's better to store the credentials in environment variables. I am attaching the code snippet that will do the job.
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST = os.environ.get('EMAIL_HOST')
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_PORT = 587

Sending Godaddy email via Django using python

I have these settings
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'username#domain.com'
SERVER_EMAIL = 'username#domain.com'
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
If I set other combinations like
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'username#domain.com'
SERVER_EMAIL = 'username#domain.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
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.
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 = 'myemail#GoDaddyDomain.com'
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 :("
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
I managed to decide to access the site
https://sso.secureserver.net/?app=emailsetup&realm=pass&
It seems that when accessing, you can enable email for external use.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER='aXXXX#xxxx'
EMAIL_HOST_PASSWORD='AsgGSDAGSasdsagas'
DEFAULT_FROM_EMAIL='aXXXX#xxxx'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
It worked for me
It's been a while but, maybe the answer can help somebody else. I just talked to GoDaddy about the issue and the needed configration they told me was like,
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtpout.secureserver.net'
EMAIL_HOST_USER = env('EMAIL_HOST_USER')
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 80
EMAIL_USE_SSL = False
EMAIL_USE_TLS = True
these are the django config settings but, I'm sure that it can be copied to other platforms.
Also, the email dns configration they provided was,
use 'smtpout.asia.secureserver.net' as EMAIL_HOST in Django settings.py. you can refer to the GoDaddy email help page link.
https://in.godaddy.com/help/mail-server-addresses-and-ports-for-business-email-24071
In my case, this way work for me:
#settings.py
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='smtpout.secureserver.net'
EMAIL_PORT=465
EMAIL_USE_SSL=True
EMAIL_USE_TLS=False
EMAIL_HOST_USER='your#domain'
EMAIL_HOST_PASSWORD='yourpass'
ADMIN_EMAIL='your#domain'

SMTP AUTH extension not supported by server - Sending emails through a private host

I registered a domain and a private email using namecheap.com. I am trying to send an email from this private email. However, I get the error in the title.
In my settings.py, I have these settings:
EMAIL_HOST = 'mail.privateemail.com'
EMAIL_HOST_USER = 'contact#mysite.com'
EMAIL_HOST_PASSWORD = 'my password'
EMAIL_PORT = 587
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
And I am trying to send my mail through a view:
send_mail(
'Subject here',
'Here is the message.',
'contact#mysite.com',
['myname#gmail.com'],
fail_silently=False,
)
I get this error :
SMTP AUTH extension not supported by server.
This is happening because you have conflicting settings:
EMAIL_PORT = 587 # Port 587 is reserved for TLS
EMAIL_USE_TLS = False # But you have disabled TLS
You either need to set EMAIL_USE_TLS to True or use the default port for unencrypted connections (25).
I was searching answer for this since 4 hours. I still dont know why this configuration works for me, but yes, IT WORKS for me.
I simply removed,
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
from my settings.py, and add below configuration in settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'username#domain.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
Remove the following config since "SMTP AUTH extension not supported by" your EMAIL_HOST:
EMAIL_HOST_PASSWORD = 'my password'
EMAIL_PORT = 587
I was using a server that is not Gmail by default and turns out to be a port issue, I found that I was using the wrong port, I changed it to 465 for SMTP with TLS, Thanks to this link..
So here are the settings I used:
EMAIL_PORT = 465
EMAIL_USE_TLS = True

Django email configuration with Bluehost email server

I am new to Bluehost and Django and I am trying to setup a "password reset via email" function on my Bluehost server with Django. I've tried different combinations on setting the host and port number but for some reason it never worked. So here's what I had: (I am currently only working on my local computer.)
On Bluehost website where I can configure my email account, it lists:
Manual Settings
Mail Server Username: admin+my_host.com
Incoming Mail Server: mail.my_host.com
Incoming Mail Server: (SSL) box664.bluehost.com
Outgoing Mail Server: mail.my_host.com (server requires authentication) port 26
Outgoing Mail Server: (SSL) box664.bluehost.com (server requires authentication) port 465
Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)
Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)
In settings.py I have the emails configured as: (I will list two combinations and the corresponding error message)
combination 1
DEFAULT_FROM_EMAIL = 'admin#my_host.com'
SERVER_EMAIL = 'admin#my_host.com'
EMAIL_USE_TLS = False
EMAIL_HOST = 'box664.bluehost.com'
EMAIL_HOST_PASSWORD = 'my_email_password'
EMAIL_HOST_USER = 'admin+my_host.com'
EMAIL_PORT = 465
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
error message: Exception Value: Connection unexpectedly closed
combination 2
DEFAULT_FROM_EMAIL = 'admin#my_host.com'
SERVER_EMAIL = 'admin#my_host.com'
EMAIL_USE_TLS = True
EMAIL_HOST = 'mail.my_host.com'
EMAIL_HOST_PASSWORD = 'my_email_password'
EMAIL_HOST_USER = 'admin+my_host.com'
EMAIL_PORT = 26
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
error message: Exception Value: (535, 'Incorrect authentication data')
Could anyone give me some suggestions where I did wrong? Any help is appreciated.
The following settings:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False
EMAIL_HOST = 'mail.yourdomain.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'no-reply#yourdomain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
worked for me. My django version I tested with is 1.8.8.
Bluehost smtp settings details are explained here.
I exactly dunno what the problem is, but I have faced the same problem. I think it has something to do with SMTP/SSL. So what I used this: https://github.com/perenecabuto/django-sendmail-backend
Then I used this configuration in settings.py:
EMAIL_USE_SSL = False
EMAIL_USE_TLS= False
EMAIL_HOST = 'box###.bluehost.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'someone#example.com'
EMAIL_HOST_PASSWORD = 'password'
Hope it helps.

Categories

Resources