참고: Python 2.7은 2024년 1월 31일 지원 종료됩니다. 기존 Python 2.7 애플리케이션을 계속 실행하고 트래픽을 받을 수 있습니다. 그러나 지원 종료 날짜 이후에는 해당 런타임을 사용하는 애플리케이션의 재배포를 App Engine에서 차단할 수 있습니다.
지원되는 최신 Python 버전으로 마이그레이션하는 것이 좋습니다.
전송은 비동기로 수행됩니다. mail.send_mail() 함수 및 EmailMessage.send() 메서드는 메일 서비스에 메시지 데이터를 전송한 후 반환합니다. 메일 서비스는 메시지를 큐에 넣은 후 전송을 시도하고, 대상 메일 서버를 사용할 수 없으면 작업을 재시도합니다. 오류 및 반송 메시지는 이메일 메시지의 보내는 사람 주소로 전송됩니다.
시작하기 전에
보내는 사람의 이메일을 승인된 보내는 사람으로 등록해야 합니다. 자세한 내용은 이메일을 보낼 수 있는 사람을 참조하세요.
mail.send_mail()를 사용하여 메일 보내기
mail.send_mail() 함수를 사용하여 메일을 보내려면 보내는 사람, 받는 사람, 제목, 메시지 본문 등 이메일 메시지의 필드를 매개변수로 사용합니다. 예를 들면 다음과 같습니다.
mail.send_mail(sender=sender_address,to="Albert Johnson <Albert.Johnson@example.com>",subject="Your account has been approved",body="""Dear Albert:Your example.com account has been approved. You can now visithttp://www.example.com/ and sign in using your Google Account toaccess new features.Please let us know if you have any questions.The example.com Team""")
EmailMessage를 사용하여 메일 보내기
EmailMessage 클래스가 포함된 객체를 사용하여 메일을 전송하려면 이메일 메시지 필드를 EmailMessage 생성자로 전달하고 인스턴스 속성을 사용하여 메시지를 업데이트합니다.
EmailMessage.send() 메서드는 인스턴스 속성으로 표시된 이메일 메시지를 전송합니다. 애플리케이션은 속성을 수정하고 send() 메서드를 다시 호출하여 EmailMessage 인스턴스를 재사용할 수 있습니다.
message=mail.EmailMessage(sender=sender_address,subject="Your account has been approved")message.to="Albert Johnson <Albert.Johnson@example.com>"message.body="""Dear Albert:Your example.com account has been approved. You can now visithttp://www.example.com/ and sign in using your Google Account toaccess new features.Please let us know if you have any questions.The example.com Team"""message.send()
다음 예는 이메일 주소 확인을 위한 메시지 전송을 보여줍니다.
classUserSignupHandler(webapp2.RequestHandler):"""Serves the email address sign up form."""defpost(self):user_address=self.request.get('email_address')ifnotmail.is_email_valid(user_address):self.get()# Show the form again.else:confirmation_url=create_new_user_confirmation(user_address)sender_address=('Example.com Support <{}@appspot.gserviceaccount.com>'.format(app_identity.get_application_id()))subject='Confirm your registration'body="""Thank you for creating an account!Please confirm your email address by clicking on the link below:{}""".format(confirmation_url)mail.send_mail(sender_address,user_address,subject,body)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-06(UTC)"],[[["The mail API offers two methods for sending emails: the `mail.send_mail()` function and the `EmailMessage` class."],["Email sending is asynchronous, meaning the function or method returns immediately after sending the message data to the mail service, which then queues and attempts delivery."],["To use this API you need to register your sender emails as authorized senders."],["The `mail.send_mail()` function takes email fields as parameters, whereas the `EmailMessage` class uses attributes of an instance to construct and send emails."],["This API can only run in first-generation runtimes in the App Engine standard environment."]]],[]]