Skip to content
Snippets Groups Projects
Commit dd0ec77d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

work in progress

parent 2014222f
No related branches found
No related tags found
1 merge request!42Email functionality
Pipeline #
...@@ -22,6 +22,15 @@ ALLOWED_HOSTS = ['prc.parkinson.lu', 'localhost'] ...@@ -22,6 +22,15 @@ ALLOWED_HOSTS = ['prc.parkinson.lu', 'localhost']
DEBUG = True DEBUG = True
EMAIL_USE_TLS = False
EMAIL_USE_SSL = False
EMAIL_HOST = 'smtp-3.uni.lu'
EMAIL_HOST_USER = 'piotr.gawron@uni.lu'
EMAIL_HOST_PASSWORD = '123qweasdzxc'
EMAIL_PORT = 25
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = 'piotr.gawron@uni.lu'
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
......
# coding=utf-8
from django.core import mail
from django.core.mail.backends.smtp import EmailBackend
from web.models import ConfigurationItem
from web.models.constants import EMAIL_HOST_CONFIGURATION_TYPE, EMAIL_PASSWORD_CONFIGURATION_TYPE, \
EMAIL_PORT_CONFIGURATION_TYPE, EMAIL_USER_CONFIGURATION_TYPE, EMAIL_CONFIGURATION_TYPE
class EmailSender(object):
def __init__(self):
host = ConfigurationItem.objects.get(type=EMAIL_HOST_CONFIGURATION_TYPE).value
port = ConfigurationItem.objects.get(type=EMAIL_PORT_CONFIGURATION_TYPE).value
user = ConfigurationItem.objects.get(type=EMAIL_USER_CONFIGURATION_TYPE).value
password = ConfigurationItem.objects.get(type=EMAIL_PASSWORD_CONFIGURATION_TYPE).value
self.backend = EmailBackend(host=host, port=port, username=user, password=password, use_tls=False,
use_ssl=False)
# self.connection = mail.get_connection(backend=self.backend)
self.connection = mail.get_connection()
def send_email(self, subject, body, to):
email_from = ConfigurationItem.objects.get(type=EMAIL_CONFIGURATION_TYPE).value
print email_from
print subject
print body
print to
mail.EmailMessage(subject, body, email_from, [to], connection=self.connection).send(fail_silently=False)
# coding=utf-8
from django.test import TestCase
from web.email import EmailSender
from web.models import ConfigurationItem
from web.models.constants import EMAIL_HOST_CONFIGURATION_TYPE, EMAIL_PASSWORD_CONFIGURATION_TYPE, \
EMAIL_PORT_CONFIGURATION_TYPE, EMAIL_USER_CONFIGURATION_TYPE, EMAIL_CONFIGURATION_TYPE
class TestEmailSender(TestCase):
def setUp(selfself):
host = ConfigurationItem.objects.get(type=EMAIL_HOST_CONFIGURATION_TYPE)
host.value = "smtp.uni.lu"
host.save()
port = ConfigurationItem.objects.get(type=EMAIL_PORT_CONFIGURATION_TYPE)
port.value="25"
port.save()
# uni doesn't check it
user = ConfigurationItem.objects.get(type=EMAIL_USER_CONFIGURATION_TYPE)
password = ConfigurationItem.objects.get(type=EMAIL_PASSWORD_CONFIGURATION_TYPE)
email_from = ConfigurationItem.objects.get(type=EMAIL_CONFIGURATION_TYPE)
email_from.value = "piotr.gawron@uni.lu"
email_from.save()
def test_send_email(self):
email_sender = EmailSender()
email_sender.send_email("test", "test body<br/>and content", "piotr.gawron@uni.lu")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment