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():
...
@@ -65,7 +65,7 @@ def data():
path
=
msgfolder
+
prefix
+
"/"
path
=
msgfolder
+
prefix
+
"/"
os
.
mkdir
(
path
)
os
.
mkdir
(
path
)
key
=
request
.
files
.
get
(
'key'
)
#
key = request.files.get('key')
#if key:
#if key:
# print("desencripto deploy.py 70")
# print("desencripto deploy.py 70")
# request.files['key'].save(path + "rand.key.enc")
# request.files['key'].save(path + "rand.key.enc")
...
@@ -149,7 +149,7 @@ def clean():
...
@@ -149,7 +149,7 @@ def clean():
p
.
deletepath
(
folder
)
p
.
deletepath
(
folder
)
continue
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
# 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
:
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
)
os
.
system
(
"rm -r "
+
folder
)
...
...
services.py
View file @
af801d8
...
@@ -117,18 +117,15 @@ class Mail(ServiceBase):
...
@@ -117,18 +117,15 @@ class Mail(ServiceBase):
self
.
__password
=
config
.
SMTP_password
self
.
__password
=
config
.
SMTP_password
def
iniciarConn
(
self
):
def
iniciarConn
(
self
):
#print("inicializo cliente default mail")
self
.
s
=
smtplib
.
SMTP
(
host
=
config
.
SMTP_HOST
,
port
=
config
.
SMTP_PORT
)
self
.
s
=
smtplib
.
SMTP
(
host
=
config
.
SMTP_HOST
,
port
=
config
.
SMTP_PORT
)
self
.
s
.
starttls
()
self
.
s
.
starttls
()
self
.
s
.
login
(
self
.
__username
,
self
.
__password
)
self
.
s
.
login
(
self
.
__username
,
self
.
__password
)
#def send(self,data):
# N = self._send(data)
# return(N)
def
send
(
self
,
data
,
stadotel
,
stadomail
):
def
send
(
self
,
data
,
stadotel
,
stadomail
):
types
=
json
.
loads
(
data
[
Table
.
type
])
types
=
json
.
loads
(
data
[
Table
.
type
])
info
=
json
.
loads
(
data
[
Table
.
info
])
info
=
json
.
loads
(
data
[
Table
.
info
])
self
.
TextoaEnviar
=
""
#import ipdb; ipdb.set_trace()
msg
=
MIMEMultipart
()
msg
=
MIMEMultipart
()
Cr
=
ValidacionCorreo
()
Cr
=
ValidacionCorreo
()
msg
[
'From'
]
=
self
.
Usuario
(
info
)
msg
[
'From'
]
=
self
.
Usuario
(
info
)
...
@@ -142,10 +139,12 @@ class Mail(ServiceBase):
...
@@ -142,10 +139,12 @@ class Mail(ServiceBase):
return
(
succ
)
return
(
succ
)
for
file
in
types
:
for
file
in
types
:
filepath
=
data
[
Table
.
path
]
+
file
filepath
=
data
[
Table
.
path
]
+
file
if
file
==
'texto'
:
self
.
TextoaEnviar
=
filepath
#por si es envio masivo
MIME
=
self
.
MIMEmode
(
file
,
filepath
,
types
[
file
])
MIME
=
self
.
MIMEmode
(
file
,
filepath
,
types
[
file
])
msg
.
attach
(
MIME
)
msg
.
attach
(
MIME
)
succ
[
file
]
=
True
succ
[
file
]
=
True
#self.s.send_message(msg)
try
:
try
:
if
not
msg
[
'From'
]
in
stadomail
.
MailRompedor
:
if
not
msg
[
'From'
]
in
stadomail
.
MailRompedor
:
self
.
Envio
(
msg
,
info
,
stadomail
)
self
.
Envio
(
msg
,
info
,
stadomail
)
...
@@ -155,7 +154,6 @@ class Mail(ServiceBase):
...
@@ -155,7 +154,6 @@ class Mail(ServiceBase):
print
(
"ROMPIO ALGO EN EL ENVIO"
)
print
(
"ROMPIO ALGO EN EL ENVIO"
)
stadomail
.
MailRompedor
.
append
(
msg
[
'From'
])
stadomail
.
MailRompedor
.
append
(
msg
[
'From'
])
succ
[
file
]
=
False
succ
[
file
]
=
False
#stadomail.MailRompedor = []
return
succ
return
succ
def
Usuario
(
self
,
info
):
def
Usuario
(
self
,
info
):
...
@@ -166,21 +164,37 @@ class Mail(ServiceBase):
...
@@ -166,21 +164,37 @@ class Mail(ServiceBase):
return
(
u
)
return
(
u
)
def
Envio
(
self
,
msg
,
info
,
stadomail
):
def
Envio
(
self
,
msg
,
info
,
stadomail
):
#import ipdb; ipdb.set_trace()
try
:
try
:
smtp
=
info
[
"smtp"
]
smtp
=
info
[
"smtp"
]
except
:
except
:
smtp
=
False
smtp
=
False
#import ipdb; ipdb.set_trace()
if
smtp
==
False
:
if
smtp
==
False
:
#print(info, type(info))
#print(info, type(info))
print
(
"mail sale por default"
)
print
(
"mail sale por default"
)
self
.
iniciarConn
()
self
.
iniciarConn
()
n
=
self
.
s
.
send_message
(
msg
)
n
=
self
.
s
.
send_message
(
msg
)
elif
smtp
[
"host"
]
==
"MAILMASIVO"
:
n
=
self
.
sendGrid
(
msg
,
smtp
)
else
:
else
:
print
(
"mail sale por cliente"
)
self
.
ControlMail
(
stadomail
,
smtp
)
self
.
ControlMail
(
stadomail
,
smtp
)
n
=
self
.
SMTPcliente
(
msg
,
smtp
)
n
=
self
.
SMTPcliente
(
msg
,
smtp
)
return
(
n
)
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
):
def
ControlMail
(
self
,
stadomail
,
smtp
):
est
=
stadomail
.
ChequearMailServer
(
User
=
smtp
[
"username"
],
est
=
stadomail
.
ChequearMailServer
(
User
=
smtp
[
"username"
],
Pass
=
smtp
[
"password"
],
Pass
=
smtp
[
"password"
],
...
@@ -190,6 +204,7 @@ class Mail(ServiceBase):
...
@@ -190,6 +204,7 @@ class Mail(ServiceBase):
raise
NameError
(
"Mail_Server_Fall"
)
raise
NameError
(
"Mail_Server_Fall"
)
def
SMTPcliente
(
self
,
msg
,
Serversmtp
):
def
SMTPcliente
(
self
,
msg
,
Serversmtp
):
print
(
"mail sale por cliente"
)
print
(
Serversmtp
,
type
(
Serversmtp
))
print
(
Serversmtp
,
type
(
Serversmtp
))
dg
=
smtplib
.
SMTP
(
host
=
Serversmtp
[
"host"
],
port
=
Serversmtp
[
"port"
])
dg
=
smtplib
.
SMTP
(
host
=
Serversmtp
[
"host"
],
port
=
Serversmtp
[
"port"
])
dg
.
starttls
()
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