클라우드/Azure
Azure Communication Services 이메일 전송 예시 코드
쓱은감자
2025. 5. 29. 10:38
Azure Communication Services(ACS)를 통해 간단하게 이메일을 보내는 코드 예시
✅ 필요한 패키지 설치
pip install azure-communication-email
✅ Python 코드 예시
from azure.communication.email import EmailClient, EmailContent, EmailAddress, EmailMessage
# 연결 문자열: Azure Portal에서 Communication Service 리소스 -> Access Keys에서 확인 가능
connection_string = "endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>"
# Email 클라이언트 생성
client = EmailClient.from_connection_string(connection_string)
# 이메일 구성
message = EmailMessage(
sender="DoNotReply@<your-resource>.azurecomm.net", # 포털에서 등록한 verified sender
content=EmailContent(
subject="테스트 메일입니다.",
plain_text="안녕하세요. Azure Communication Services 이메일 테스트입니다."
),
recipients={"to": [EmailAddress(email="받는사람@example.com", display_name="홍길동")]}
)
# 메일 발송
response = client.send(message)
print("메일 전송 요청 완료. Message ID:", response['message_id'])
- sender는 ACS에서 등록된 발신자 주소여야 합니다. (azurecomm.net 도메인이거나 도메인 인증된 주소)
- connection_string은 Azure Portal에서 확인 가능합니다.
반응형