Install | Topics | Beyond Lino

Tips & tricks

How to store secret credentials

Install the dotenv Python package:

pip install python-dotenv

Create a file ~/.env with this content:

EMAIL_HOST_USER=joe
EMAIL_HOST_PASSWORD=kkFUW8TRSXVgeq

In your settings.py file:

import dotenv; secrets = dotenv.dotenv_values()
EMAIL_HOST_USER = secrets['EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = secrets['EMAIL_HOST_PASSWORD']

Helo command rejected: need fully-qualified hostname

You may receive this error message when sending from a machine that has no public FQDN to an SMTP server that has strict smtpd_helo_restrictions.

Here is a hack to make Django use your IP address rather than socket.getfqdn() when sending email. Add the following to your settings.py file:

from socket import gethostname, gethostbyname
from django.core.mail import DNS_NAME
ip_addr = gethostbyname(gethostname())
DNS_NAME._fqdn = "[{}]".format(ip_addr)
print("Using your IP address [{}] as FQDN in HELO".format(ip_addr))