Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
message-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit af801d86
authored
2020-07-18 20:05:06 -0300
by
Juan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
principio de integracion con relay
1 parent
0a7b9686
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
deploy.py
services.py
deploy.py
View file @
af801d8
...
...
@@ -65,7 +65,7 @@ def data():
path
=
msgfolder
+
prefix
+
"/"
os
.
mkdir
(
path
)
key
=
request
.
files
.
get
(
'key'
)
#
key = request.files.get('key')
#if key:
# print("desencripto deploy.py 70")
# request.files['key'].save(path + "rand.key.enc")
...
...
@@ -149,7 +149,7 @@ def clean():
p
.
deletepath
(
folder
)
continue
mtime
=
os
.
path
.
getmtime
(
folder
)
mtime
=
os
.
path
.
getmtime
(
folder
)
#reveer esta funcion
# Si la carpeta existe por más de X segundos, borrala
if
int
(
now
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
))
-
int
(
time
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
))
>
operation_timer
:
os
.
system
(
"rm -r "
+
folder
)
...
...
services.py
View file @
af801d8
...
...
@@ -117,18 +117,15 @@ class Mail(ServiceBase):
self
.
__password
=
config
.
SMTP_password
def
iniciarConn
(
self
):
#print("inicializo cliente default mail")
self
.
s
=
smtplib
.
SMTP
(
host
=
config
.
SMTP_HOST
,
port
=
config
.
SMTP_PORT
)
self
.
s
.
starttls
()
self
.
s
.
login
(
self
.
__username
,
self
.
__password
)
#def send(self,data):
# N = self._send(data)
# return(N)
def
send
(
self
,
data
,
stadotel
,
stadomail
):
types
=
json
.
loads
(
data
[
Table
.
type
])
info
=
json
.
loads
(
data
[
Table
.
info
])
self
.
TextoaEnviar
=
""
#import ipdb; ipdb.set_trace()
msg
=
MIMEMultipart
()
Cr
=
ValidacionCorreo
()
msg
[
'From'
]
=
self
.
Usuario
(
info
)
...
...
@@ -142,10 +139,12 @@ class Mail(ServiceBase):
return
(
succ
)
for
file
in
types
:
filepath
=
data
[
Table
.
path
]
+
file
if
file
==
'texto'
:
self
.
TextoaEnviar
=
filepath
#por si es envio masivo
MIME
=
self
.
MIMEmode
(
file
,
filepath
,
types
[
file
])
msg
.
attach
(
MIME
)
succ
[
file
]
=
True
#self.s.send_message(msg)
try
:
if
not
msg
[
'From'
]
in
stadomail
.
MailRompedor
:
self
.
Envio
(
msg
,
info
,
stadomail
)
...
...
@@ -155,7 +154,6 @@ class Mail(ServiceBase):
print
(
"ROMPIO ALGO EN EL ENVIO"
)
stadomail
.
MailRompedor
.
append
(
msg
[
'From'
])
succ
[
file
]
=
False
#stadomail.MailRompedor = []
return
succ
def
Usuario
(
self
,
info
):
...
...
@@ -166,21 +164,37 @@ class Mail(ServiceBase):
return
(
u
)
def
Envio
(
self
,
msg
,
info
,
stadomail
):
#import ipdb; ipdb.set_trace()
try
:
smtp
=
info
[
"smtp"
]
except
:
smtp
=
False
#import ipdb; ipdb.set_trace()
if
smtp
==
False
:
#print(info, type(info))
print
(
"mail sale por default"
)
self
.
iniciarConn
()
n
=
self
.
s
.
send_message
(
msg
)
elif
smtp
[
"host"
]
==
"MAILMASIVO"
:
n
=
self
.
sendGrid
(
msg
,
smtp
)
else
:
print
(
"mail sale por cliente"
)
self
.
ControlMail
(
stadomail
,
smtp
)
n
=
self
.
SMTPcliente
(
msg
,
smtp
)
return
(
n
)
def
sendGrid
(
self
,
msg
,
smtp
):
#import ipdb; ipdb.set_trace()
texto
=
open
(
self
.
TextoaEnviar
,
"r"
)
.
read
()
Mail
=
smtp
[
"username"
]
KeyAPI
=
smtp
[
"password"
]
headers
=
{
'Content-type'
:
'application/json'
,
"Authorization"
:
"Bearer {}"
.
format
(
KeyAPI
)}
data
=
{
"personalizations"
:
[{
"to"
:
[{
"email"
:
msg
[
'To'
]}]}],
"from"
:
{
"email"
:
Mail
},
"subject"
:
msg
[
'Subject'
],
"content"
:
[{
"type"
:
"text/plain"
,
"value"
:
str
(
texto
)}]}
requests
.
post
(
url
=
"https://api.sendgrid.com/v3/mail/send"
,
data
=
json
.
dumps
(
data
),
headers
=
headers
)
return
(
True
)
def
ControlMail
(
self
,
stadomail
,
smtp
):
est
=
stadomail
.
ChequearMailServer
(
User
=
smtp
[
"username"
],
Pass
=
smtp
[
"password"
],
...
...
@@ -190,6 +204,7 @@ class Mail(ServiceBase):
raise
NameError
(
"Mail_Server_Fall"
)
def
SMTPcliente
(
self
,
msg
,
Serversmtp
):
print
(
"mail sale por cliente"
)
print
(
Serversmtp
,
type
(
Serversmtp
))
dg
=
smtplib
.
SMTP
(
host
=
Serversmtp
[
"host"
],
port
=
Serversmtp
[
"port"
])
dg
.
starttls
()
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment