summaryrefslogtreecommitdiff
path: root/src/jwebmail/webmail.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jwebmail/webmail.py')
-rw-r--r--src/jwebmail/webmail.py45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py
index af60774..7e63307 100644
--- a/src/jwebmail/webmail.py
+++ b/src/jwebmail/webmail.py
@@ -1,4 +1,12 @@
from urllib.parse import urlparse
+from smtplib import (
+ SMTP_SSL,
+ SMTPHeloError,
+ SMTPAuthenticationError,
+ SMTPNotSupportedError,
+ SMTPException,
+)
+from email.message import EmailMessage
from flask import abort, current_app, flash, redirect, render_template, request, url_for
from flask_babel import gettext, lazy_gettext
@@ -200,21 +208,28 @@ def sendmail():
if not form.validate():
abort(400)
- mail = {
- "to": form.to.data,
- "message": form.content.data,
- "subject": form.subject.data,
- "cc": form.cc.data,
- "bcc": form.bcc.data,
- "reply": form.answer_to.data,
- "attach": form.attachments.data,
- "from": "",
- }
-
- error = send_mail(mail)
-
- if error:
- return render_template("writemail.html", warning=gettext("error_send")), 400
+ # mail = { "attach": form.attachments.data }
+ mail = EmailMessage()
+ mail["to"] = form.answer_to.data
+ mail["subject"] = form.subject.data
+ mail["cc"] = form.cc.data
+ mail["bcc"] = form.bcc.data
+ mail["reply"] = form.answer_to.data
+ mail.set_content(form.content.data)
+
+ try:
+ with SMTP_SSL(
+ current_app.config["JWEBMAIL"]["WRITE_MAILS"]["SMTPS_SERVER"]
+ ) as smtp:
+ smtp.login(current_user.id, current_user.password)
+ smtp.send_message(mail)
+ except (
+ SMTPHeloError,
+ SMTPAuthenticationError,
+ SMTPNotSupportedError,
+ SMTPException,
+ ):
+ return render_template("writemail.html", form=form, warning=gettext("error_send")), 400
flash(gettext("succ_send"))
return redirect(url_for("displayheaders"), 303)