HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/smtp.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZe�e�ZdZ	zddl
ZddlZddl
ZddlZdZ	Wn	ey6YnwdZdd�Z									dd
d�ZdS)
a�
Module for Sending Messages via SMTP

.. versionadded:: 2014.7.0

:depends:   - smtplib python module
:configuration: This module can be used by either passing a jid and password
    directly to send_message, or by specifying the name of a configuration
    profile in the minion config, minion pillar, or master config.

    For example:

    .. code-block:: yaml

        my-smtp-login:
            smtp.server: smtp.domain.com
            smtp.tls: True
            smtp.sender: admin@domain.com
            smtp.username: myuser
            smtp.password: verybadpass

    The resourcename refers to the resource that is using this account. It is
    user-definable, and optional. The following configurations are both valid:

    .. code-block:: yaml

        my-smtp-login:
            smtp.server: smtp.domain.com
            smtp.tls: True
            smtp.sender: admin@domain.com
            smtp.username: myuser
            smtp.password: verybadpass

        another-smtp-login:
            smtp.server: smtp.domain.com
            smtp.tls: True
            smtp.sender: admin@domain.com
            smtp.username: myuser
            smtp.password: verybadpass

�NFTZsmtpcCstrtSdS)zG
    Only load this module if smtplib is available on this minion.
    )Fz2This module is only loaded if smtplib is available)�HAS_LIBS�__virtualname__�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/smtp.py�__virtual__Bsr�Message from Salt�Truec

Cs�|r!td|�}
|
�d�}|
�d�}|
�d�}|
�d�}|
�d�}|	r4tjj��}|�tjj�|��ntjj�|�}||d<||d<||d	<d
d�|�	d�D�}z|d
vr\t
�|�}
nt
�|�}
Wnt
jy|}z
t�d|�WYd}~dSd}~ww|d
vr�|
��|
�d�r�z|
��Wn-t
jy�t�d�YdSt
jy�t�d�YdSty�t�d�YdSw|
��|r�|r�z|
�||�Wnt
jy�}zt�d�WYd}~dSd}~ww|	�r'|	D]9}tj�|�}tjj�|d��}tjj j!|�"�|d�}Wd�n	1�swYd|�d�|d<|�|�q�z|
�#|||�$��WnBt
j%�yCt�d�YdSt
j�ySt�d�YdSt
j&�ydt�d|�YdSt
j'�ytt�d�YdSw|
�(�dS)ad
    Send a message to an SMTP recipient. To send a message to multiple     recipients, the recipients should be in a comma-seperated Python string.     Designed for use in states.

    CLI Examples:

    .. code-block:: bash

        salt '*' smtp.send_msg 'admin@example.com' 'This is a salt module test' profile='my-smtp-account'
        salt '*' smtp.send_msg 'admin@example.com,admin2@example.com' 'This is a salt module test for multiple recipients' profile='my-smtp-account'
        salt '*' smtp.send_msg 'admin@example.com' 'This is a salt module test' username='myuser' password='verybadpass' sender='admin@example.com' server='smtp.domain.com'
        salt '*' smtp.send_msg 'admin@example.com' 'This is a salt module test' username='myuser' password='verybadpass' sender='admin@example.com' server='smtp.domain.com' attachments="['/var/log/messages']"
    z
config.optionzsmtp.serverzsmtp.tlszsmtp.senderz
smtp.usernamez
smtp.passwordZSubjectZFromZTocSsg|]}|���qSr)�strip)�.0�rrrr�
<listcomp>uszsend_msg.<locals>.<listcomp>�,)r�truez
Exception: %sNFZSTARTTLSu8The server didn’t reply properly to the HELO greeting.z3The server does not support the STARTTLS extension.z<SSL/TLS support is not available to your Python interpreter.zSMTP Authentication Failure�rb)�Namezattachment; filename="�"zContent-DispositionzAll recipients were refused.u"The server didn’t accept the %s.z1The server replied with an unexpected error code.T))Z__salt__�get�email�mime�	multipartZ
MIMEMultipart�attach�textZMIMEText�split�smtplibZSMTP_SSLZSMTP�socket�gaierror�log�debugZehloZhas_extnZstarttlsZ
SMTPHeloErrorZ
SMTPException�RuntimeErrorZloginZSMTPAuthenticationError�os�path�basename�salt�utils�filesZfopenZapplicationZMIMEApplication�readZsendmail�	as_stringZSMTPRecipientsRefusedZSMTPSenderRefusedZ
SMTPDataError�quit)Z	recipient�message�subjectZsenderZserverZuse_ssl�username�passwordZprofile�attachmentsZcreds�msgZ
recipientsZsmtpconn�_error�f�name�finZattrrr�send_msgKs�





���


��
���


�r2)rNNrNNNN)�__doc__�loggingrrZsalt.utils.filesr"�	getLogger�__name__rrZemail.mime.applicationrZemail.mime.multipartZemail.mime.textr�ImportErrorrrr2rrrr�<module>s6*
��