3

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?

  • if you wanted to run your own smtp server instead of using an external smtp service, then you would want to run it as its own container instead of inside your django application container. – programmerq May 16 '18 at 17:44
  • @programmerq okay, i see. What should i do to set that up? What image or software inside Docker? –  May 16 '18 at 20:06

2 Answers2

0

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:

mbuechmann
  • 5,413
  • 5
  • 27
  • 40
  • Actually, I do not want to use Google's smtp servers, rather, i plan on having email sent to a gmail address from contact form –  May 16 '18 at 20:05
  • Thanks for the answer –  May 17 '18 at 09:58
0

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