now is better than never

[airflow] Email Operator 본문

데이터 엔지니어링/airflow

[airflow] Email Operator

김초송 2023. 6. 19. 18:28

이메일 오퍼레이터 (Email Operator)

  • 이메일을 전송해주는 오퍼레이터
  • 사전작업
    1. Gmail → 설정 → 모든 설정보기 → 전달 및 POP / IMAP → IMAP사용
    2. 구글 계정 관리 → 보안 → 2단계 인증 → 앱 비밀번호 (구글 이메일 서버 사용 시 인증)
    3. docker-compose.yaml 편집
      • environment 안에
AIRFLOW__SMTP__SMTP_HOST: ‘smtp.gmail.com’ 
AIRFLOW__SMTP__SMTP_USER: ‘{gmail 계정}’ 
AIRFLOW__SMTP__SMTP_PASSWORD: ‘{앱비밀번호}’ 
AIRFLOW__SMTP__SMTP_PORT: 587 AIRFLOW__SMTP__SMTP_MAIL_FROM: ‘{gmail 계정}’

Email Operator DAG 

from airflow import DAG
import pendulum
import datetime
from airflow.operators.email import EmailOperator

with DAG(
    dag_id="dags_email_operator",
    schedule="0 8 1 * *", # 매월 1일 아침 8시
    start_date=pendulum.datetime(2023, 6, 1, tz="Asia/Seoul"),
    catchup=False,
) as dag:
    send_email_task = EmailOperator(
        task_id='send_email_task',
        to='', # 받는 사람
        cc='', # 참조
        subject='Airflow 성공 알림', # 제목
        html_content='Airflow 작업이 완료되었습니다.' # 내용
    )

 

5번째 시도만에 성공... 

하지만 그 과정에는 앱 비밀번호 윈도우로 해봣다가 다시 맥으로 해봣다가 

yaml 파일을 몇번을 수정하고ㅠ 결국 되긴했는데 왜 됐는지 모르겠음

dag 을 삭제할까 말까 하다가.. state clear 하고 다시 yaml 파일 다시 편집하니까 어찌저찌 됐는데 

왜 이제까지 안되다가 갑자기 됐는지 모르겠음 ^^ 환장하겠네...

'데이터 엔지니어링 > airflow' 카테고리의 다른 글

[airflow] op_args  (0) 2023.06.22
[airflow] Python Operator  (2) 2023.06.22
[airflow] 외부 쉘 스크립트 수행  (0) 2023.06.18
[airflow] CRON 스케쥴  (0) 2023.06.17
[airflow] DAG 생성 (bash)  (0) 2023.06.16