Docker SMTP Server for Django Container SMTP backend - django

I am looking to have one of my django docker containers setup a smtp backend so I can send input from a contact form to a gmail address as well as possibly send out an email when someone puts in their email to subscribe for updates: https://docs.djangoproject.com/en/1.11/topics/email/#smtp-backend
How do I go about setting up the SMTP server? Is it a separate docker container? How do I set it up?

The email backend is just an imported module. You can just use it like it is described in the docs: https://docs.djangoproject.com/en/1.11/topics/email/#email-backends
Before that, you have to configure the data for the smtp server. You just have to configure the settings, like your smtp host, username and password, etc. Here are the docs to configure it: https://docs.djangoproject.com/en/1.11/topics/email/#smtp-backend
You can use an existing smtp server. If you have a package with a domain you probably have a an email account included.
There is no need for another container. But you can setup your own in a a separate container. There are already some docker-ready solutions present. Here are a few:
https://github.com/namshi/docker-smtp
https://mailu.io/
https://github.com/tomav/docker-mailserver

just do changes in some file
#add it in docker_compose.yml
maildev:
image: maildev/maildev
ports:
- "49180:80"
# add it in your settings.py file
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'maildev'
EMAIL_PORT = 25
# then run docker-compose up -d
# when it done then run docker build -t <your tag Name> .
happy coding.......
refrence link:
[1]: https://melvinkoh.me/configure-and-send-email-in-django-for-both-development-and-production-cjye4y0l7000nuns1m43vstaq

Related

How can I send an email from Apache superset?

I'm facing Authentication unsuccessful error when I try to send mail from Apache Superset.
I checked the document's SMTP integration chapter:https://apache-superset.readthedocs.io/en/latest/installation.html
I changed SMTP_PASSWORD parameter and I entered password manually in my config.py file like SMTP_PASSWORD = "'xxx!!'" (I added '' because my password includes special character like '!'. Also, I tried SMTP_PASSWORD="xx!!" but also I'm getting error.
smtplib.SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful')
I can login with my SMTP user via browser (Exchange). Could you please help me to solve this issue?
Apache Superset version: 1.3.2
Python version:3.8
OS version: RHEL 8
Thanks
You might be able to poke at this by checking your SMTP connection from inside your Superset instance.
From where your Superset instance should be sending the emails, start a Python script and try:
import smtplib
server = smtplib.SMTP('smtpservername.yourdomain', yourportnumber)
If that command fails or hangs indefinitely, you know there's a connection problem. You might try connecting to the GMail SMTP server or another known-to-work set of credentials and seeing if that works to narrow it down.
For instance, if running Superset with docker-compose you would enter the worker container with docker exec -it superset_worker /bin/bash, run python, and try this there.
My scheduled reports were failing and doing this helped me isolate a cause: my Superset instance could not connect to the target unauthenticated SMTP server.

Django can not send email when deployed by nginx+uwsgi+Django

I use Django to send email,everything is OK when running on development environment, which uses command "python manage.py runserver 0.0.0.0:8100". But in the production environment which deployed by nginx+uwsgi+Django do not work.
Here is the code:
#Email settings
EMAIL_HOST='smtp.exmail.qq.com'
EMAIL_PORT='465'
EMAIL_HOST_USER='sender#qq.cn'
EMAIL_HOST_PASSWORD='password'
EMAIL_USE_SSL=True
RECEIVE_EMIAL_LIST=['receiver#qq.com']
send_mail('subject','content',setting.EMAIL_HOST_USER,setting.RECEIVE_EMIAL_LIST, fail_silently=False)
Have you checked that your production environment has the same network settings as the development environment?
Have you tried to ping or telnet the SMTP server from production?
Is possible that the production host is in a DMZ or in a subnet that has restricted access to the SMTP server you are trying to reach.
EMAIL_HOST = 'smtp.qq.com'
change EMAIL_PORT='465' to EMAIL_PORT = 587, with no quotes.
EMAIL_HOST_USER = 'abc#qq.com' # try to use your real email address.
RECEIVE_EMIAL_LIST=['receiver#qq.com'] to RECEIVE_EMIAL_LIST=['receiver#qq.com'**,**] # add a comma at the end of the list is a good habit.

Redirect http to https in Django (using sslserver)

I have a django project working with HTTPS using django sslserver.I want http to be redirected to https. I tried adding SECURE_SSL_REDIRECT = True which does not seem to have any effect.
Similarly to test if my redirection was right, I tried the following on a test project.
Created a new django project
Added SECURE_SSL_REDIRECT = True to the settings.py file. Here now, when I try to run the server with http it redirects to https. But asof now my server does not support https cause of which desired web page is not displayed.
Installed sslserver
Ran the project with the command python manage.py runsslserver 8000
This succesfully redirects the webpage to https even if I open the url with http
This test redirection works fine like this. But if I already have sslserver installed ssl redirection does not seem to have any effect. I have been stuck with this problem for a while now and would really appreciate some help.
SECURE_SSL_REDIRECT settings works together with SecurityMiddleware.
Try add it to MIDDLEWARE_CLASSES in settings.py.
In addition to SECURE_SSL_REDIRECT=True in settings.py as mentioned, you need both
runsslserver on port 443
runserver on port 80
To have another service listen on port 80 for incoming http requests and do the redirect.
That works for me.
try adding to your settings.
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'

How to configure git to work witha proxy server

How can someone tweak aroud th heroku toolbelt i.e git and use a proxy server to connect to heroku. I am trying to connect but it keeps telling me machine actively denied it access. help
You can set the Git proxy using the below command in the git bash. Set for both HTTP and HTTPS proxy.
git config --global http.proxy http://username:password#proxy.server.com:8080
git config --global https.proxy http://username:password#proxy.server.com:8080
//Replace username with your proxy username
//Replace password with your proxy password
//Replace proxy.server.com with the proxy domain URL.
//Replace 8080 with the proxy port no configured on the proxy server.
Check How to configure Git proxy and How to unset the Git Proxy for more details
Set HTTP_PROXY and HTTPS_PROXY system environment variables in following format if proxy sever requires authentication:
HTTP_PROXY = http://username:password#proxy.server.com:portNumber
HTTPS_PROXY = https://username:password#proxy.server.com:portNumber
use HTTP_PROXY environemnt variable
e.g. HTTP_PROXY=http://localhost:9999

Django email backend with local smtp

I want send email from django application.
I want send an email to my mail id from other username without authentication. Just i used smtp server for the authenticated mail.In the django mail api How it is supposed to send an mail with the local smtp?
As stated on the docs: https://docs.djangoproject.com/en/dev/topics/email/?from=olddocs you need to:
On your settings.py define the following:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
Then, in another shell run the following command:
python -m smtpd -n -c DebuggingServer localhost:1025
That will run a dummy SMTP server, that actually will not send any email but you'll be able to see the output and check if that's correct. If you want to actually send your emails during development, you will need to install a SMTP server like sendmail and use that in your configuration.