jck
jck

Reputation: 2058

Is it possible to send an email in django through a microsoft exchange server?

If yes, how? I was not able to find anything on google.

Upvotes: 3

Views: 6915

Answers (4)

Anay
Anay

Reputation: 579

Sending an email in Django through a Microsoft Exchange server is possible using the SMTP protocol.

Here's an example configuration:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'your.exchange.server'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '[email protected]'

Replace your.exchange.server, [email protected], and yourpassword with the appropriate values for your Exchange server and email account.

Upvotes: -2

wanikwai
wanikwai

Reputation: 1

Here is what my settings.py looked like and it works.

# Email Backend Service
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'yourexchangservername'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

# Use environment variables for sensitive information
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
DEFAULT_FROM_EMAIL = os.environ.get('DEFAULT_FROM_EMAIL')

Upvotes: 0

DragonBobZ
DragonBobZ

Reputation: 2444

In case someone is still in need of some help here... It took me a while to figure out what the EMAIL_HOST setting needed to be for an out-of-the-box MSE configuration.

EMAIL_HOST = 'outlook.office365.com'
EMAIL_HOST_USER = [email protected]
EMAIL_HOST_PASSWORD = Y0urP@$$w0rd
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

The above configuration is working fine for me using Django's default email backend.

Upvotes: 2

Tom Werner
Tom Werner

Reputation: 319

SMTP on Exchange shouldn't be any different to any other mail server. You may hit issues of anonymous access is not allowed for relaying. If only integrated authentication is enabled, have a look at;

SMTP through Exchange using Integrated Windows Authentication (NTLM) using Python

Also ensure the IP of the Django box is added to the list of relay IPs in Exchange (if enabled).

Upvotes: 1

Related Questions