Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Krause, Benjamin
email_proxy
Commits
aa4ff70c
Commit
aa4ff70c
authored
Aug 19, 2020
by
Benjamin Krause
Browse files
Adjust mail provider class
parent
de0bb236
Changes
1
Show whitespace changes
Inline
Side-by-side
app/mail_provider.py
View file @
aa4ff70c
...
...
@@ -2,6 +2,7 @@ import email
import
imaplib
import
smtplib
from
email.message
import
EmailMessage
from
enum
import
Enum
from
pydantic
import
BaseModel
...
...
@@ -10,17 +11,26 @@ from app.user import User
from
app.utils
import
subject_identifier
class
Encryption
(
Enum
):
SSL_TLS
=
"ssl_tls"
STARTTLS
=
"starttls"
class
MailProvider
(
BaseModel
):
name
:
str
base_url
:
str
imap_url
:
str
imap_port
:
int
=
993
imap_encryption
:
Encryption
=
Encryption
.
STARTTLS
smtp_url
:
str
smtp_port
:
int
smtp_port
:
int
=
587
smtp_encryption
:
Encryption
=
Encryption
.
STARTTLS
def
send_mail
(
self
,
from_user
:
User
,
to_user
:
User
,
message
:
EmailMessage
):
try
:
with
smtplib
.
SMTP
(
self
.
smtp_url
,
self
.
smtp_port
)
as
server
:
server
.
ehlo
()
server
.
starttls
()
server
.
ehlo
()
server
.
login
(
from_user
.
mail
,
from_user
.
password
)
server
.
sendmail
(
from_user
.
mail
,
to_user
.
mail
,
message
.
as_string
())
return
True
...
...
@@ -54,7 +64,9 @@ class MailProvider(BaseModel):
print
(
e
)
def
imap_login
(
self
,
user
:
User
)
->
imaplib
.
IMAP4_SSL
:
imap
=
imaplib
.
IMAP4_SSL
(
self
.
imap_url
)
imap
=
imaplib
.
IMAP4_SSL
(
self
.
imap_url
,
self
.
smtp_port
)
imap
.
starttls
()
imap
.
ehlo
()
imap
.
login
(
user
.
mail
,
user
.
password
)
return
imap
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment