Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- pandas
- data analyst
- 데이터 사이언티스트
- Data Scientist
- deep learning
- Data Science
- SQL
- ai
- data analysis
- 파이썬
- Deeplearning
- numpy
- EDA
- CNN
- 범죄통계
- AISCHOOL
- data
- machinelearing
- 데이터 분석가
- 멋쟁이사자처럼
- MachineLearning
- DNN
- Tableau
- 데이터분석가
- Machine Learning
- python
- machineleaning
Archives
- Today
- Total
Molybdenum의 개발기록
[TIL] 4일차_IMAP 본문
▶ SMTP(Simple Mail Transfer Protocol) -> 간단하게 메일을 보내기 위한 약속
- sMTP 메일 서버를 연결한다.
- SMTP 메일 서버에 로그인한다.
- SMTP 메일 서버로 메일을 보낸다.
import smtplib
from email.message import EmailMessage
import imghdr -> 이미지 파일의 확장자가 변경되면 자동으로 변경될 수 있도록함
SMTP_SERVER = "smtp.gmail.com"
SMTP_PORT = 465
message = EmailMessage()
message.set_content("복습중입니다.")
message["Subject"]="이것은 제목입니다." -> header에 들어감
message["From"] = "이메일계정"
message["To"] = "받는이메일계정"
with open("codelion.png","rb") as image:
image_file = image.read()
image_type = imghdr.what('codelion',image_file)
message.add_attachment(image_file,maintype='image',subtype='image_type')
smtplib.SMTP.SSL(SMTP_SERVER,SMTP_PORT) -> GMAIL은 SSL을 요구함
smtp.login("이메일계정","비밀번호")
smtp.send_message()
smtp.quit()
▶ MINE
- 이메일을 만든다.
- 이메일에 내용을 담는다.
- 발신자, 수신자를 설정한다.
- rb = read binary / wb = write binary / ab = append binary
- add_attaachment(...) = 메일 내용안에 일반적인 텍스트가 아닌 mixed 타입의 메일일 경우 사용
- image
- maintype
- subtype
▶정규표현식
= 문자열에서 나타나는 특정패턴을 조건으로 주고 문자열이 적합한지 유무를 판단
codelion.example@ gmial .
^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$
^/$ = 시작과 끝
[a-zA-Z0-9.+_-]+ = a부터 z까지, A부터 Z까지, 0부터 9까지, ., +, _, - 가 1회 이상 반복된다.
@ = 그뒤에 @가 붙는다.
[a-zA-Z0-9]+ = a부터 z까지, A부터 Z까지, 0부터 9까지 가 1회 이상 반복된다.
\. = 그뒤에 .이 온다.
[a-zA-Z]{2,3} = a부터 z까지 A부터 Z까지가 최소 2회, 최대 3번 반복된다.
import smtplib
from email.message import EmailMessage
import imghdr -> 이미지 파일의 확장자가 변경되면 자동으로 변경될 수 있도록함
import re
SMTP_SERVER = "smtp.gmail.com"
SMTP_PORT = 465
def sendEmail(addr):
reg = "^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$"
if bool(re.match(reg,"codelion.example@gmail.com")): -> 내용이 있다면 true 없다면 none
smtp.send_message()
print("정상적인 이메일 주소입니다.")
else:
print("유효한 이메일 주소가 아닙니다."
message = EmailMessage()
message.set_content("복습중입니다.")
message["Subject"]="이것은 제목입니다." -> header에 들어감
message["From"] = "이메일계정"
message["To"] = "받는이메일계정"
with open("codelion.png","rb") as image:
image_file = image.read()
image_type = imghdr.what('codelion',image_file)
message.add_attachment(image_file,maintype='image',subtype='image_type')
smtplib.SMTP.SSL(SMTP_SERVER,SMTP_PORT) -> GMAIL은 SSL을 요구함
smtp.login("이메일계정","비밀번호")
sendEmail("받는이메일계정")
smtp.quit()
'TIL' 카테고리의 다른 글
[TIL] 6일차_PYTHON_02 (0) | 2023.02.28 |
---|---|
[TIL] 6일차_PYTHON_01 (0) | 2023.02.28 |
[TIL] 4일차_GoogleTranslate (0) | 2023.02.28 |
[TIL] 4일차_API 날씨 정보 받아오기 (0) | 2023.02.28 |
[TIL] 4일차_실시간 검색어 Crawling (0) | 2023.02.28 |
Comments