Gmail API를 활용한 이메일 자동화 RPA 프로그램 Features: - Gmail API 인증 및 연동 - 키워드/발신자 기반 자동 분류 - 조건별 자동 답장 기능 - 통계 리포트 생성 - 커스터마이징 가능한 JSON 설정 Modules: - gmail_automation.py: 메인 프로그램 - gmail_auth.py: Gmail API 인증 - email_classifier.py: 이메일 분류 로직 - auto_reply.py: 자동 답장 로직 - config.json.example: 설정 예시 Documentation: - 상세한 README.md (설치, 사용법, 트러블슈팅) - Google Cloud Console 설정 가이드 - 실제 효과 측정 데이터
103 lines
2.7 KiB
Python
103 lines
2.7 KiB
Python
"""
|
|
이메일 분류 모듈
|
|
"""
|
|
|
|
import re
|
|
|
|
|
|
class EmailClassifier:
|
|
"""이메일 자동 분류 클래스"""
|
|
|
|
def __init__(self, config):
|
|
"""
|
|
초기화
|
|
|
|
Args:
|
|
config: 분류 규칙이 포함된 설정
|
|
"""
|
|
self.rules = config.get('classification_rules', [])
|
|
|
|
def classify(self, email_data):
|
|
"""
|
|
이메일 분류
|
|
|
|
Args:
|
|
email_data: 이메일 정보 (subject, sender, body)
|
|
|
|
Returns:
|
|
분류 카테고리 정보 또는 None
|
|
"""
|
|
subject = email_data.get('subject', '').lower()
|
|
sender = email_data.get('sender', '').lower()
|
|
body = email_data.get('body', '').lower()
|
|
snippet = email_data.get('snippet', '').lower()
|
|
|
|
# 전체 텍스트
|
|
full_text = f"{subject} {body} {snippet}"
|
|
|
|
for rule in self.rules:
|
|
# 키워드 검사
|
|
keywords = rule.get('keywords', [])
|
|
if keywords:
|
|
if any(keyword.lower() in full_text for keyword in keywords):
|
|
return rule
|
|
|
|
# 발신자 도메인 검사
|
|
from_domains = rule.get('from_domains', [])
|
|
if from_domains:
|
|
sender_domain = self.extract_domain(sender)
|
|
if sender_domain in from_domains:
|
|
return rule
|
|
|
|
# 정규식 패턴 검사
|
|
patterns = rule.get('patterns', [])
|
|
if patterns:
|
|
for pattern in patterns:
|
|
if re.search(pattern, full_text):
|
|
return rule
|
|
|
|
return None
|
|
|
|
def extract_domain(self, email_address):
|
|
"""이메일 주소에서 도메인 추출"""
|
|
match = re.search(r'@([\w\.-]+)', email_address)
|
|
if match:
|
|
return match.group(1).lower()
|
|
return ''
|
|
|
|
def get_priority(self, email_data):
|
|
"""이메일 우선순위 판단"""
|
|
category = self.classify(email_data)
|
|
|
|
if category:
|
|
priority = category.get('priority', 'normal')
|
|
return priority
|
|
|
|
return 'normal'
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# 테스트
|
|
config = {
|
|
"classification_rules": [
|
|
{
|
|
"name": "업무",
|
|
"keywords": ["회의", "프로젝트"],
|
|
"label": "업무/중요",
|
|
"priority": "high"
|
|
}
|
|
]
|
|
}
|
|
|
|
classifier = EmailClassifier(config)
|
|
|
|
test_email = {
|
|
'subject': '프로젝트 회의 일정',
|
|
'sender': 'test@company.com',
|
|
'body': '내일 오전 10시 회의',
|
|
'snippet': ''
|
|
}
|
|
|
|
result = classifier.classify(test_email)
|
|
print(f"분류 결과: {result}")
|