rpa-suite 1.3.7__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/PKG-INFO +3 -2
  2. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/README.md +1 -1
  3. rpa_suite-1.4.0/rpa_suite/core/email.py +131 -0
  4. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite.egg-info/PKG-INFO +3 -2
  5. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite.egg-info/requires.txt +1 -0
  6. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/setup.py +2 -2
  7. rpa_suite-1.3.7/rpa_suite/core/email.py +0 -343
  8. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/LICENSE +0 -0
  9. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/__init__.py +0 -0
  10. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/__init__.py +0 -0
  11. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/clock.py +0 -0
  12. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/date.py +0 -0
  13. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/dir.py +0 -0
  14. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/file.py +0 -0
  15. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/log.py +0 -0
  16. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/print.py +0 -0
  17. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/regex.py +0 -0
  18. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/core/validate.py +0 -0
  19. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/__create_log_dir.py +0 -0
  20. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/__create_ss_dir.py +0 -0
  21. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/__init__.py +0 -0
  22. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/_functions_logger.py +0 -0
  23. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/_logger.py +0 -0
  24. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/_printer.py +0 -0
  25. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/_variables.py +0 -0
  26. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/functions/_variables_uru.py +0 -0
  27. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite/suite.py +0 -0
  28. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite.egg-info/SOURCES.txt +0 -0
  29. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite.egg-info/dependency_links.txt +0 -0
  30. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/rpa_suite.egg-info/top_level.txt +0 -0
  31. {rpa_suite-1.3.7 → rpa_suite-1.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rpa_suite
3
- Version: 1.3.7
3
+ Version: 1.4.0
4
4
  Summary: Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.
5
5
  Author: Camilo Costa de Carvalho
6
6
  Author-email: camilo.carvalho@triasoftware.com.br
@@ -24,6 +24,7 @@ Requires-Dist: email_validator
24
24
  Requires-Dist: loguru
25
25
  Requires-Dist: typing
26
26
  Requires-Dist: pillow
27
+ Requires-Dist: pyautogui
27
28
  Dynamic: author
28
29
  Dynamic: author-email
29
30
  Dynamic: classifier
@@ -185,7 +186,7 @@ Lançamento: *20/02/2024*
185
186
 
186
187
  Status: Em desenvolvimento.
187
188
 
188
- ### Notas da atualização: 1.3.7
189
+ ### Notas da atualização: 1.4.0
189
190
 
190
191
  - Correções de bugs em diversas funções relacionadas a tempo: *exec_at_hour* , *wait_for_exec* , *exec_and_wait*
191
192
  - Correções de bugs com tempo superior a 10 minutos nas funções de data: *get_hms* e *get_dma*
@@ -148,7 +148,7 @@ Lançamento: *20/02/2024*
148
148
 
149
149
  Status: Em desenvolvimento.
150
150
 
151
- ### Notas da atualização: 1.3.7
151
+ ### Notas da atualização: 1.4.0
152
152
 
153
153
  - Correções de bugs em diversas funções relacionadas a tempo: *exec_at_hour* , *wait_for_exec* , *exec_and_wait*
154
154
  - Correções de bugs com tempo superior a 10 minutos nas funções de data: *get_hms* e *get_dma*
@@ -0,0 +1,131 @@
1
+ # /sender_smtp.py
2
+
3
+ import smtplib, os
4
+ from email.mime.image import MIMEImage
5
+ from email.mime.multipart import MIMEMultipart
6
+ from email.mime.text import MIMEText
7
+ from email.mime.base import MIMEBase
8
+ from email import encoders
9
+ from rpa_suite.functions._printer import alert_print, error_print, success_print
10
+ from rpa_suite.core.validate import email_validator
11
+
12
+
13
+ class Email():
14
+
15
+ smtp_server:str = "smtp.hostinger.com",
16
+ smtp_port:str = 465,
17
+ email_user:str = "your_email@email.com",
18
+ email_password:str = "password",
19
+ email_to: str = "to@email.com",
20
+ attachments: list[str] = [],
21
+ subject_title: str = 'Test title',
22
+ body_message: str = '<p>Testing message body</p>'
23
+ auth_tls: bool = False,
24
+
25
+ def __init__(self):
26
+ ...
27
+
28
+ def send_smtp(
29
+ self,
30
+ email_user:str,
31
+ email_password:str,
32
+ email_to: str,
33
+ subject_title: str = 'Test title',
34
+ body_message: str = '<p>Testing message body</p>',
35
+ attachments: list[str] = [],
36
+ smtp_server:str = "smtp.hostinger.com",
37
+ smtp_port:str = 465,
38
+ auth_tls: bool = False,
39
+ display_message: bool = True,
40
+ ):
41
+
42
+ """
43
+ Envia um e-mail utilizando o servidor SMTP especificado.
44
+
45
+ Args:
46
+ smtp_server (str, optional): Endereço do servidor SMTP.
47
+ Padrão: "smtp.hostinger.com".
48
+ smtp_port (str, optional): Porta do servidor SMTP.
49
+ Padrão: 465.
50
+ email_user (str, optional): Usuário (e-mail) para autenticação no servidor SMTP.
51
+ Padrão: "bot@vettracode.com".
52
+ email_password (str, optional): Senha para autenticação no servidor SMTP.
53
+ Padrão: "Bot@#2025".
54
+ email_to (str, optional): Endereço de e-mail do destinatário.
55
+ Padrão: "camilo.costa1993@gmail.com".
56
+ attachments (list[str], optional): Lista de caminhos de arquivos para anexar ao e-mail.
57
+ Padrão: [].
58
+ subject_title (str, optional): Título (assunto) do e-mail.
59
+ Padrão: 'titulo teste'.
60
+ body_message (str, optional): Corpo da mensagem do e-mail, em formato HTML.
61
+ Padrão: '<p>mensagem de teste</p>'.
62
+
63
+ Returns:
64
+ None: Esta função não retorna nenhum valor explicitamente, mas imprime mensagens de sucesso ou falha no envio do e-mail.
65
+ """
66
+
67
+ try:
68
+ self.smtp_server = smtp_server
69
+ self.smtp_port = smtp_port
70
+ self.email_user = email_user
71
+ self.email_password = email_password
72
+ self.email_to = email_to
73
+ self.subject_title = subject_title
74
+ self.body_message = body_message
75
+ self.attachments = attachments
76
+ self.auth_tls = auth_tls
77
+
78
+ # Criando a mensagem
79
+ msg = MIMEMultipart()
80
+ msg['From'] = self.email_user
81
+ msg['To'] = ', '.join(self.email_to) if isinstance(self.email_to, list) else self.email_to
82
+ msg['Subject'] = str(self.subject_title)
83
+
84
+ # Corpo do e-mail
85
+ body = str(self.body_message)
86
+ msg.attach(MIMEText(body, 'html'))
87
+
88
+ # Anexos (opcional)
89
+ if self.attachments:
90
+ from email.mime.base import MIMEBase
91
+ from email import encoders
92
+ import os
93
+
94
+ for attachment_path in self.attachments:
95
+ try:
96
+ with open(attachment_path, "rb") as attachment:
97
+ part = MIMEBase("application", "octet-stream")
98
+ part.set_payload(attachment.read())
99
+ encoders.encode_base64(part)
100
+ part.add_header(
101
+ "Content-Disposition",
102
+ f"attachment; filename= {os.path.basename(attachment_path)}",
103
+ )
104
+ msg.attach(part)
105
+
106
+ except Exception as e:
107
+ error_print(f"Erro ao anexar o arquivo {attachment_path}: {str(e)}")
108
+
109
+ try:
110
+ if self.auth_tls:
111
+ # Conectando ao servidor SMTP com TLS
112
+ server = smtplib.SMTP(self.smtp_server, self.smtp_port)
113
+ server.starttls()
114
+ server.login(self.email_user, self.email_password)
115
+ else:
116
+ # Conectando ao servidor SMTP com SSL
117
+ server = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)
118
+ server.login(self.email_user, self.email_password)
119
+
120
+ # Enviando o e-mail
121
+ server.sendmail(self.email_user, self.email_to, msg.as_string())
122
+ if display_message: success_print("E-mail enviado com sucesso!")
123
+
124
+ # Encerrando a conexão
125
+ server.quit()
126
+
127
+ except Exception as e:
128
+ alert_print(f"Falha ao enviar o e-mail: {str(e)}")
129
+
130
+ except Exception as e:
131
+ error_print(f"Ocorreu um erro geral na função sendmail: {str(e)}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rpa_suite
3
- Version: 1.3.7
3
+ Version: 1.4.0
4
4
  Summary: Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.
5
5
  Author: Camilo Costa de Carvalho
6
6
  Author-email: camilo.carvalho@triasoftware.com.br
@@ -24,6 +24,7 @@ Requires-Dist: email_validator
24
24
  Requires-Dist: loguru
25
25
  Requires-Dist: typing
26
26
  Requires-Dist: pillow
27
+ Requires-Dist: pyautogui
27
28
  Dynamic: author
28
29
  Dynamic: author-email
29
30
  Dynamic: classifier
@@ -185,7 +186,7 @@ Lançamento: *20/02/2024*
185
186
 
186
187
  Status: Em desenvolvimento.
187
188
 
188
- ### Notas da atualização: 1.3.7
189
+ ### Notas da atualização: 1.4.0
189
190
 
190
191
  - Correções de bugs em diversas funções relacionadas a tempo: *exec_at_hour* , *wait_for_exec* , *exec_and_wait*
191
192
  - Correções de bugs com tempo superior a 10 minutos nas funções de data: *get_hms* e *get_dma*
@@ -4,3 +4,4 @@ email_validator
4
4
  loguru
5
5
  typing
6
6
  pillow
7
+ pyautogui
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='rpa_suite',
5
- version='1.3.7',
5
+ version='1.4.0',
6
6
  packages=find_packages(),
7
7
  description='Conjunto de ferramentas essenciais para Automação RPA com Python, que facilitam o dia a dia de desenvolvimento.',
8
8
  long_description_content_type='text/markdown',
@@ -23,5 +23,5 @@ setup(
23
23
  'Topic :: Software Development :: Libraries :: Python Modules'
24
24
  ],
25
25
  keywords='basic-tools, email-tools, email-validation, file-tools, simple-functions, rpa-tools, rpa-functions, Tools, Rpa, Automation, RPA, Automação, Python, Ferramentas de RPA, Automação de Processos, Biblioteca Python para RPA, Bot, Robô, Ferramentas de automação',
26
- install_requires=['colorama', 'colorlog', 'email_validator', 'loguru', 'typing', 'pillow'],
26
+ install_requires=['colorama', 'colorlog', 'email_validator', 'loguru', 'typing', 'pillow', 'pyautogui'],
27
27
  )
@@ -1,343 +0,0 @@
1
- # /sender_smtp.py
2
-
3
- import smtplib, os
4
- from email.mime.image import MIMEImage
5
- from email.mime.multipart import MIMEMultipart
6
- from email.mime.text import MIMEText
7
- from email.mime.base import MIMEBase
8
- from email import encoders
9
- from rpa_suite.functions._printer import alert_print, error_print, success_print
10
- from rpa_suite.core.validate import email_validator
11
-
12
-
13
- """
14
- smtp_server:str = "smtp.hostinger.com",
15
- smtp_port:str = 465,
16
- email_user:str = "bot@vettracode.com",
17
- email_password:str = "Bot@#2025",
18
- email_to: str = "camilo.costa1993@gmail.com",
19
- attachments: list[str] = [],
20
- subject_title: str = 'titulo teste',
21
- body_message: str = '<p>mensagem de teste</p>'
22
- """
23
-
24
- class Email():
25
-
26
- smtp_server:str = "smtp.hostinger.com",
27
- smtp_port:str = 465,
28
- email_user:str = "your_email@email.com",
29
- email_password:str = "password",
30
- email_to: str = "to@email.com",
31
- attachments: list[str] = [],
32
- subject_title: str = 'Test title',
33
- body_message: str = '<p>Testing message body</p>'
34
- auth_tls: bool = False,
35
-
36
- def __init__(self):
37
- ...
38
-
39
- def send_smtp(
40
- self,
41
- email_user:str,
42
- email_password:str,
43
- email_to: str,
44
- subject_title: str = 'Test title',
45
- body_message: str = '<p>Testing message body</p>',
46
- attachments: list[str] = [],
47
- smtp_server:str = "smtp.hostinger.com",
48
- smtp_port:str = 465,
49
- auth_tls: bool = False,
50
- display_message: bool = True,
51
- ):
52
-
53
- """
54
- Envia um e-mail utilizando o servidor SMTP especificado.
55
-
56
- Args:
57
- smtp_server (str, optional): Endereço do servidor SMTP.
58
- Padrão: "smtp.hostinger.com".
59
- smtp_port (str, optional): Porta do servidor SMTP.
60
- Padrão: 465.
61
- email_user (str, optional): Usuário (e-mail) para autenticação no servidor SMTP.
62
- Padrão: "bot@vettracode.com".
63
- email_password (str, optional): Senha para autenticação no servidor SMTP.
64
- Padrão: "Bot@#2025".
65
- email_to (str, optional): Endereço de e-mail do destinatário.
66
- Padrão: "camilo.costa1993@gmail.com".
67
- attachments (list[str], optional): Lista de caminhos de arquivos para anexar ao e-mail.
68
- Padrão: [].
69
- subject_title (str, optional): Título (assunto) do e-mail.
70
- Padrão: 'titulo teste'.
71
- body_message (str, optional): Corpo da mensagem do e-mail, em formato HTML.
72
- Padrão: '<p>mensagem de teste</p>'.
73
-
74
- Returns:
75
- None: Esta função não retorna nenhum valor explicitamente, mas imprime mensagens de sucesso ou falha no envio do e-mail.
76
- """
77
-
78
- try:
79
- self.smtp_server = smtp_server
80
- self.smtp_port = smtp_port
81
- self.email_user = email_user
82
- self.email_password = email_password
83
- self.email_to = email_to
84
- self.subject_title = subject_title
85
- self.body_message = body_message
86
- self.attachments = attachments
87
- self.auth_tls = auth_tls
88
-
89
- # Criando a mensagem
90
- msg = MIMEMultipart()
91
- msg['From'] = self.email_user
92
- msg['To'] = ', '.join(self.email_to) if isinstance(self.email_to, list) else self.email_to
93
- msg['Subject'] = str(self.subject_title)
94
-
95
- # Corpo do e-mail
96
- body = str(self.body_message)
97
- msg.attach(MIMEText(body, 'html'))
98
-
99
- # Anexos (opcional)
100
- if self.attachments:
101
- from email.mime.base import MIMEBase
102
- from email import encoders
103
- import os
104
-
105
- for attachment_path in self.attachments:
106
- try:
107
- with open(attachment_path, "rb") as attachment:
108
- part = MIMEBase("application", "octet-stream")
109
- part.set_payload(attachment.read())
110
- encoders.encode_base64(part)
111
- part.add_header(
112
- "Content-Disposition",
113
- f"attachment; filename= {os.path.basename(attachment_path)}",
114
- )
115
- msg.attach(part)
116
-
117
- except Exception as e:
118
- error_print(f"Erro ao anexar o arquivo {attachment_path}: {str(e)}")
119
-
120
- try:
121
- if self.auth_tls:
122
- # Conectando ao servidor SMTP com TLS
123
- server = smtplib.SMTP(self.smtp_server, self.smtp_port)
124
- server.starttls()
125
- server.login(self.email_user, self.email_password)
126
- else:
127
- # Conectando ao servidor SMTP com SSL
128
- server = smtplib.SMTP_SSL(self.smtp_server, self.smtp_port)
129
- server.login(self.email_user, self.email_password)
130
-
131
- # Enviando o e-mail
132
- server.sendmail(self.email_user, self.email_to, msg.as_string())
133
- if display_message: success_print("E-mail enviado com sucesso!")
134
-
135
- # Encerrando a conexão
136
- server.quit()
137
-
138
- except Exception as e:
139
- alert_print(f"Falha ao enviar o e-mail: {str(e)}")
140
-
141
- except Exception as e:
142
- error_print(f"Ocorreu um erro geral na função sendmail: {str(e)}")
143
-
144
-
145
-
146
- def send_by_smtp( self,
147
- email_from: str,
148
- pass_from: str,
149
- email_to: list[str],
150
- subject_title: str,
151
- body_message: str,
152
- image_footer: str = None,
153
- attachments: list[str] = None,
154
- type_content: str = 'html',
155
- smtp_server: str = 'smtp.office365.com',
156
- smtp_port: int = 587,
157
- authentication_tls: bool = True,
158
- display_message: bool = True,
159
- ) -> dict:
160
-
161
- """
162
- Function responsible for sending emails ``(SMTP)``, accepts ``list of recipients`` and possibility
163
- of ``attaching files``. \n
164
-
165
- Parameters:
166
- ----------
167
- ``email_from: str`` - email from who will send the email.
168
- ``pass_from: str`` - password of the account used, advised to isolate the password elsewhere.
169
- ``email_to: list[str]`` - list of emails to which the emails will be sent.
170
- ``subject_title: str`` - email title.
171
- ``body_message: str``- body message of the email.
172
- ``image_footer: str`` - image footer of body message of the email.
173
- ``attachments: list[str]`` - list with path of attachments if any. (default None).
174
- ``type_content: str`` - type of message content can be 'plain' or 'html' (default 'html').
175
- ``smtp_server: str`` - server to be used to connect with the email account (default 'smtp.office365.com')
176
- ``smtp_port: int`` - port to be used on this server (default 587 - TLS), commum use 465 for SSL authentication
177
- ``authentication_tls: bool`` - authentication method (default True), if False use SSL authentication
178
-
179
- Return:
180
- ----------
181
- >>> type:dict
182
- a dictionary with all information that may be necessary about the emails.
183
- Respectively being:
184
- * 'success': bool - if there was at least one successful shipment
185
- * 'all_mails': list - list of all emails parameterized for sending
186
- * 'valid_mails': list - list of all valid emails for sending
187
- * 'invalid_mails': list - list of all invalid emails for sending
188
- * 'qt_mails_sent': int - effective quantity that was sent
189
- * 'attchament': bool - if there are attachments
190
- * 'qt_attach': int - how many attachments were inserted
191
-
192
- Description: pt-br
193
- ----------
194
- Função responsavel por enviar emails ``(SMTP)``, aceita ``lista de destinatários`` e possibilidade
195
- de ``anexar arquivos``. \n
196
-
197
- Parametros:
198
- ----------
199
- ``email_from: str`` - email de quem ira enviar o email.
200
- ``pass_from: str`` - senha da conta utilizada, aconselhado isolar a senha em outro local.
201
- ``email_to: list[str]`` - lista de emails para os quais serão enviados os emails.
202
- ``subject_title: str`` - titulo do email.
203
- ``body_message: str``- mensagem do corpo do email.
204
- ``image_footer: str`` - imagem de rodapé do corpo do email.
205
- ``attachments: list[str]`` - lista com caminho de anexos se houver. (default None).
206
- ``type_content: str`` - tipo de conteudo da mensagem pode ser 'plain' ou 'html' (default 'html').
207
- ``smtp_server: str`` - servidor a ser utilizado para conectar com a conta de email (default 'smtp.office365.com')
208
- ``smtp_port: int`` - porta a ser utilizada nesse servidor (default 587 - TLS), comum usar 465 para autenticação por SSL
209
- ``authentication_tls: bool`` - metódo de autenticação (default True), caso Falso usa autenticação por SSL
210
-
211
- Retorno:
212
- ----------
213
- >>> type:dict
214
- um dicionário com todas informações que podem ser necessarias sobre os emails.
215
- Sendo respectivamente:
216
- * 'success': bool - se houve pelo menos um envio com sucesso
217
- * 'all_mails': list - lista de todos emails parametrizados para envio
218
- * 'valid_mails': list - lista de todos emails validos para envio
219
- * 'invalid_mails': list - lista de todos emails invalidos para envio
220
- * 'qt_mails_sent': int - quantidade efetiva que foi realizado envio
221
- * 'attchament': bool - se há anexos
222
- * 'qt_attach': int - quantos anexos foram inseridos
223
- """
224
-
225
- try:
226
- # Local Variables
227
- result: dict = {
228
- 'success': bool,
229
- 'all_mails': list,
230
- 'valid_mails': list,
231
- 'invalid_mails': list,
232
- 'qt_mails_sent': int,
233
- 'attchament': bool,
234
- 'qt_attach': int
235
- }
236
- email_valido = []
237
- email_invalido = []
238
-
239
- # Preprocessing
240
- result['success'] = False
241
- result['qt_mails_sent'] = 0
242
- result['attchament'] = False
243
-
244
- msg = MIMEMultipart()
245
- msg['From'] = email_from
246
- msg['Subject'] = subject_title
247
-
248
- # Email Body Content
249
- msg.attach(MIMEText(body_message, type_content))
250
-
251
- # Add image Footer
252
- if image_footer:
253
- try:
254
- with open(image_footer, 'rb') as img:
255
- msg_image = MIMEImage(img.read())
256
- msg_image.add_header('Content-ID', '<logo>')
257
- # Notice: Content-ID correlact at "cid" on tag <img> at body mail
258
- msg.attach(msg_image)
259
- except FileNotFoundError as e:
260
- alert_print(f'File Not Found! Error: {str(e)}')
261
- except Exception as e:
262
- error_print(f'An Error ocurred, during set image: <{image_footer}> as MIMEImage! Error: {str(e)}')
263
-
264
- # Add Attachment
265
- if attachments:
266
- result['qt_attach'] = 0
267
- result['attchament'] = True
268
- for path_to_attach in attachments:
269
- file_name = os.path.basename(path_to_attach)
270
- attachs = open(path_to_attach, 'rb')
271
- part = MIMEBase('application', 'octet-stream')
272
- part.set_payload((attachs).read())
273
- encoders.encode_base64(part)
274
- part.add_header('Content-Disposition', "attachment; filename= %s" % file_name)
275
- msg.attach(part)
276
- result['qt_attach'] += 1
277
- else:
278
- result['attchament'] = False
279
- result['qt_attach'] = 0
280
-
281
- # SMTP server config
282
- try:
283
-
284
- # authentication TLS False -> Using SSL authentication
285
- if authentication_tls:
286
-
287
- server_by_smtp = smtplib.SMTP(smtp_server, smtp_port)
288
- server_by_smtp.starttls()
289
- server_by_smtp.login(email_from, pass_from)
290
- email_content = msg.as_string()
291
-
292
- else: # auth with SSL
293
-
294
- # Conexão com o servidor SMTP usando SSL
295
- server_by_smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
296
- server_by_smtp.login(email_from, pass_from)
297
- email_content = msg.as_string()
298
-
299
- # Treats the email list before trying to send, keeping only valid emails
300
- try:
301
- for emails in email_to:
302
- try:
303
- v = email_validator.validate_email(emails)
304
- email_valido.append(emails)
305
-
306
- except email_validator.EmailNotValidError:
307
- email_invalido.append(emails)
308
-
309
- except Exception as e:
310
- error_print(f'Error while trying to validate email list: {str(e)}')
311
-
312
- # Attaches the treated email list to perform the sending
313
- msg['To'] = ', '.join(email_valido)
314
- for email in email_valido:
315
- try:
316
- server_by_smtp.sendmail(email_from, email, email_content)
317
- result['qt_mails_sent'] += 1
318
- result['all_mails'] = email_to
319
-
320
- except smtplib.SMTPException as e:
321
- error_print(f"The email: {email} don't sent, caused by error: {str(e)}")
322
-
323
- #server_by_smtp.quit()
324
- result['success'] = True
325
- if display_message: success_print(f'Email(s) Sent!')
326
-
327
-
328
- except smtplib.SMTPException as e:
329
- result['success'] = False
330
- error_print(f'Error while trying sent Email: {str(e)}')
331
-
332
- finally:
333
- server_by_smtp.quit()
334
-
335
- # Postprocessing
336
- result['valid_mails'] = email_valido
337
- result['invalid_mails'] = email_invalido
338
-
339
- return result
340
-
341
- except Exception as e:
342
- error_print(f'Error function: {self.send_email.__name__}! Error: {str(e)}.')
343
- return None
File without changes
File without changes
File without changes