forward questions to info mail
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.core.mail import EmailMessage
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.mail.backends.smtp import EmailBackend
|
|
||||||
|
|
||||||
|
|
||||||
NOT_SENT, SENT, PARTLY_SENT = 0, 1, 2
|
NOT_SENT, SENT, PARTLY_SENT = 0, 1, 2
|
||||||
@@ -14,20 +12,29 @@ def send_from_arbeitsministerium(subject, content, recipients, reply_to=None):
|
|||||||
auth_password=settings.EMAIL_ARBEITSMINISTERIUM_PASSWORD)
|
auth_password=settings.EMAIL_ARBEITSMINISTERIUM_PASSWORD)
|
||||||
|
|
||||||
|
|
||||||
|
def send_from_info(subject, content, recipients, reply_to=None):
|
||||||
|
return send(subject, content, settings.EMAIL_INFO, recipients,
|
||||||
|
reply_to=reply_to,
|
||||||
|
auth_user=settings.EMAIL_INFO_USER,
|
||||||
|
auth_password=settings.EMAIL_INFO_PASSWORD)
|
||||||
|
|
||||||
|
|
||||||
def send(subject, content, sender, recipients, reply_to=None,
|
def send(subject, content, sender, recipients, reply_to=None,
|
||||||
auth_user=None, auth_password=None):
|
auth_user=None, auth_password=None):
|
||||||
failed, succeeded = False, False
|
failed, succeeded = False, False
|
||||||
if type(recipients) != list:
|
if type(recipients) != list:
|
||||||
recipients = [recipients]
|
recipients = [recipients]
|
||||||
for recipient in set(recipients):
|
with mail.get_connection(username=auth_user, password=auth_password) as conn:
|
||||||
try:
|
for recipient in set(recipients):
|
||||||
mail.send_mail(subject, content, sender, recipients,
|
try:
|
||||||
auth_user=auth_user,
|
msg = mail.EmailMessage(subject, content, sender, recipients,
|
||||||
auth_password=auth_password)
|
reply_to=reply_to,
|
||||||
except Exception as e:
|
connection=conn)
|
||||||
print("Error when sending mail:", e)
|
msg.send()
|
||||||
failed = True
|
except Exception as e:
|
||||||
else:
|
print("Error when sending mail:", e)
|
||||||
succeeded = True
|
failed = True
|
||||||
|
else:
|
||||||
|
succeeded = True
|
||||||
return NOT_SENT if failed and not succeeded else SENT if not failed\
|
return NOT_SENT if failed and not succeeded else SENT if not failed\
|
||||||
and succeeded else PARTLY_SENT
|
and succeeded else PARTLY_SENT
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.conf import settings
|
||||||
from captcha.fields import CaptchaField
|
from captcha.fields import CaptchaField
|
||||||
from .models import Betrieb, Partei, PresidentCandidate, Question
|
from .models import Betrieb, Partei, PresidentCandidate, Question
|
||||||
from .mailutils import send_from_arbeitsministerium
|
from .mailutils import send_from_arbeitsministerium, send_from_info
|
||||||
|
|
||||||
|
|
||||||
class BetriebForm(forms.Form):
|
class BetriebForm(forms.Form):
|
||||||
@@ -106,6 +107,8 @@ def question_new(request):
|
|||||||
ip_address=get_client_ip(request),
|
ip_address=get_client_ip(request),
|
||||||
answered=False)
|
answered=False)
|
||||||
question.save()
|
question.save()
|
||||||
|
send_from_info(question.subject, question.content,
|
||||||
|
settings.EMAIL_INFO, reply_to=[question.email])
|
||||||
return render_confirmation(request)
|
return render_confirmation(request)
|
||||||
else:
|
else:
|
||||||
form = QuestionForm()
|
form = QuestionForm()
|
||||||
|
|||||||
@@ -146,3 +146,7 @@ EMAIL_USE_TLS = True if deployed else False
|
|||||||
EMAIL_ARBEITSMINISTERIUM = os.environ.get('EMAIL_ARBEITSMINISTERIUM', '')
|
EMAIL_ARBEITSMINISTERIUM = os.environ.get('EMAIL_ARBEITSMINISTERIUM', '')
|
||||||
EMAIL_ARBEITSMINISTERIUM_USER = os.environ.get('EMAIL_ARBEITSMINISTERIUM', '')
|
EMAIL_ARBEITSMINISTERIUM_USER = os.environ.get('EMAIL_ARBEITSMINISTERIUM', '')
|
||||||
EMAIL_ARBEITSMINISTERIUM_PASSWORD = os.environ.get('EMAIL_ARBEITSMINISTERIUM_PASSWORD', '')
|
EMAIL_ARBEITSMINISTERIUM_PASSWORD = os.environ.get('EMAIL_ARBEITSMINISTERIUM_PASSWORD', '')
|
||||||
|
|
||||||
|
EMAIL_INFO = os.environ.get('EMAIL_INFO', '')
|
||||||
|
EMAIL_INFO_USER = os.environ.get('EMAIL_INFO', '')
|
||||||
|
EMAIL_INFO_PASSWORD = os.environ.get('EMAIL_INFO_PASSWORD', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user