Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
systemprogramming project team 11
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
김가을
systemprogramming project team 11
Commits
190d439a
Commit
190d439a
authored
1 year ago
by
이종현
Browse files
Options
Downloads
Patches
Plain Diff
Update send_email.py
parent
67c8523f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
send_email.py
+7
-18
7 additions, 18 deletions
send_email.py
with
7 additions
and
18 deletions
send_email.py
+
7
−
18
View file @
190d439a
import
os
import
smtplib
import
smtplib
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email.mime.image
import
MIMEImage
from
email.mime.image
import
MIMEImage
sender_email
=
"
your_email@gmail
.com
"
sender_email
=
"
0819ljh@naver
.com
"
sender_password
=
"
your_password
"
sender_password
=
"
"
//
비밀번호는
생략하였습니다
.
recipient_email
=
"
recipient_email@example
.com
"
recipient_email
=
"
day305@naver
.com
"
smtp_server
=
"
smtp.
gmail
.com
"
smtp_server
=
"
smtp.
naver
.com
"
smtp_port
=
587
smtp_port
=
587
image_dir
=
"
path/to/your/image/directory
"
image_files
=
[
f
for
f
in
os
.
listdir
(
image_dir
)
if
f
.
lower
().
endswith
((
'
.png
'
,
'
.jpg
'
,
'
.jpeg
'
))]
latest_image
=
max
(
image_files
,
key
=
lambda
x
:
os
.
path
.
getmtime
(
os
.
path
.
join
(
image_dir
,
x
)))
image_path
=
os
.
path
.
join
(
image_dir
,
latest_image
)
msg
=
MIMEMultipart
()
msg
=
MIMEMultipart
()
msg
[
'
From
'
]
=
sender_email
msg
[
'
From
'
]
=
sender_email
msg
[
'
To
'
]
=
recipient_email
msg
[
'
To
'
]
=
recipient_email
msg
[
'
Subject
'
]
=
"
이메일 제목
"
msg
[
'
Subject
'
]
=
"
OO지역에 흡연 감지됨됨
"
body
=
"
이메일 본문 내용
"
body
=
"
OO지역에 흡연이 감지되었습니다. 지속적인흡연이감지되면 관리자는 확인부탁드리겠습니다.
"
msg
.
attach
(
MIMEText
(
body
,
'
plain
'
))
msg
.
attach
(
MIMEText
(
body
,
'
plain
'
))
with
open
(
image_path
,
"
rb
"
)
as
image_file
:
with
open
(
"
/home/pi/cat.jpg
"
,
"
rb
"
)
as
image_file
:
image
=
MIMEImage
(
image_file
.
read
())
image
=
MIMEImage
(
image_file
.
read
())
msg
.
attach
(
image
)
msg
.
attach
(
image
)
...
@@ -36,5 +27,3 @@ with smtplib.SMTP(smtp_server, smtp_port) as server:
...
@@ -36,5 +27,3 @@ with smtplib.SMTP(smtp_server, smtp_port) as server:
server
.
starttls
()
server
.
starttls
()
server
.
login
(
sender_email
,
sender_password
)
server
.
login
(
sender_email
,
sender_password
)
server
.
sendmail
(
sender_email
,
recipient_email
,
msg
.
as_string
())
server
.
sendmail
(
sender_email
,
recipient_email
,
msg
.
as_string
())
print
(
f
"
최근 이미지
'
{
latest_image
}
'
를 이메일로 전송했습니다.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment