How to create and send an email with a django based website using namecheap and digitalocean ?


In this guide I will show you how to quickly setup an email address for your django website using tools from digitalocean and namecheap. Let's get started !

Note: that I assume that you already have a domain name registered with namecheap and a django website installed on a digitalocean dropet.

Create a private email account with namecheap

First step, go to your namecheap account and click on email (in the navbar):

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Note: you can choose a trial version if you want (which is avalable during 2 months after being created).

Pick up the plan you need. For example I selected the starter plan:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

To go further you need to have a domain name. Since I already got one on namecheap I click on "Use a domain name I own with namecheap":

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Next select the domain name you want the email address attached with (if you have multiple domain names), click on continue:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Add to cart:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Confirm order:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

and "Pay now" (don't forget to scroll down on this page and check the "I have read and agreed to all Namecheap's Terms of Service and agreements")

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Next click on the red button "create mailboxes":

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

On the next page you will need to remember the records provided in the yellow box:

  • MX mx1.privateemail.com
  • MX mx2.privateemail.com
  • TXT v=spf1 include ... com all

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

On the same page click on "create mailbox now", a pop up window will then appear asking you to create an email address (you can choose for instance contact@mydomain.com):

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Log-in to your private email account

Since your create a mailbox, you can search for private email:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

and enter the email address and password you just created to log in to your account:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

The following interface should then appear (you can for example send an email to this address to check that it works well):

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Update your DigitalOcean droplet

Now let's configure your DigitalOcean droplet. (Note: if you didn't yet route a domain name you own to your digitalocean droplet, just click on create and "Domains/DNS"). Click then on the domain name for which you just created an email box:

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

click on 'MX'

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

then enter:

  • Hostname: @
  • Mail providers Mail server: mx1.privateemail.com

and click on Create Record.

Repeat the same operation with

  • Hostname: @
  • Mail providers Mail server: mx2.privateemail.com

and click on Create Record.

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Next click on TXT and enter

  • Paste TXT string here: (the txt you get on namecheap i the yellow box: v=spf1 include ... com all )
  • Hostname: @

and click on Create Record.

How to create and send an email with a django based website using namecheap and digitalocean ?
How to create and send an email with a django based website using namecheap and digitalocean ?

Done !

Send your first email with Django

Now we can send email with our django application.

First let's edit the settings.py file. If we want to make some test locally (in development). Just add the following line:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

email will not be sent but will be show in the terminal.

In production add the following lines:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST = 'mail.privateemail.com'
EMAIL_HOST_USER = 'contact@mydomain.com'
EMAIL_HOST_PASSWORD = '***********'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_USE_SSl = False
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

change 'contact@mydomain.com' and ' ' using your email box name and password.

In views.py

from django.core.mail import send_mail

and to send an email:

send_mail(
msg_title,
msg_content,
'contact@mydomain.com',
[email],
fail_silently=False)

replace msg_title, msg_content and contact@mydomain.com and enter the email address of destination.

Note: that it can be a list of email addresses

[john.doe1@gmail.com, john.doe2@gmail.com, john.doe3@gmail.com].

References

Image

of