Server IP : 85.214.239.14 / Your IP : 18.119.142.113 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/cwd/srv/modoboa/env/lib/python3.5/site-packages/modoboa_webmail/lib/ |
Upload File : |
from django.core import mail from django.template.loader import render_to_string from modoboa.lib.cryptutils import get_password from modoboa.parameters import tools as param_tools from ..exceptions import WebmailInternalError from . import get_imapconnector, clean_attachments def send_mail(request, form, posturl=None): """Email verification and sending. If the form does not present any error, a new MIME message is constructed. Then, a connection is established with the defined SMTP server and the message is finally sent. :param request: a Request object :param posturl: the url to post the message form to :return: a 2-uple (True|False, HttpResponse) """ if not form.is_valid(): editormode = request.user.parameters.get_value("editor") listing = render_to_string( "modoboa_webmail/compose.html", {"form": form, "noerrors": True, "body": form.cleaned_data.get("body", "").strip(), "posturl": posturl}, request ) return False, {"status": "ko", "listing": listing, "editor": editormode} msg = form.to_msg(request) conf = dict(param_tools.get_global_parameters("modoboa_webmail")) options = { "host": conf["smtp_server"], "port": conf["smtp_port"] } if conf["smtp_secured_mode"] == "ssl": options.update({"use_ssl": True}) elif conf["smtp_secured_mode"] == "starttls": options.update({"use_tls": True}) if conf["smtp_authentication"]: options.update({ "username": request.user.username, "password": get_password(request) }) try: with mail.get_connection(**options) as connection: msg.connection = connection msg.send() except Exception as inst: raise WebmailInternalError(str(inst)) # Copy message to sent folder sentfolder = request.user.parameters.get_value("sent_folder") get_imapconnector(request).push_mail(sentfolder, msg.message()) clean_attachments(request.session["compose_mail"]["attachments"]) del request.session["compose_mail"] return True, {}