Server IP : 85.214.239.14 / Your IP : 18.117.87.50 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 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 : /srv/modoboa/env/lib64/python3.5/site-packages/django/core/management/commands/ |
Upload File : |
import socket from django.core.mail import mail_admins, mail_managers, send_mail from django.core.management.base import BaseCommand from django.utils import timezone class Command(BaseCommand): help = "Sends a test email to the email addresses specified as arguments." missing_args_message = "You must specify some email recipients, or pass the --managers or --admin options." def add_arguments(self, parser): parser.add_argument( 'email', nargs='*', help='One or more email addresses to send a test email to.', ) parser.add_argument( '--managers', action='store_true', help='Send a test email to the addresses specified in settings.MANAGERS.', ) parser.add_argument( '--admins', action='store_true', help='Send a test email to the addresses specified in settings.ADMINS.', ) def handle(self, *args, **kwargs): subject = 'Test email from %s on %s' % (socket.gethostname(), timezone.now()) send_mail( subject=subject, message="If you\'re reading this, it was successful.", from_email=None, recipient_list=kwargs['email'], ) if kwargs['managers']: mail_managers(subject, "This email was sent to the site managers.") if kwargs['admins']: mail_admins(subject, "This email was sent to the site admins.")