(self, message: EMessage)
| 26 | self.app_password = app_password |
| 27 | |
| 28 | def send_email(self, message: EMessage) -> None: |
| 29 | msg = MIMEMultipart() |
| 30 | msg["From"] = self.from_email |
| 31 | msg["To"] = message.to if isinstance(message.to, str) else ", ".join(message.to) |
| 32 | msg["Subject"] = message.subject |
| 33 | if message.cc: |
| 34 | msg["Cc"] = ", ".join(message.cc) |
| 35 | |
| 36 | if message.bcc: |
| 37 | msg["Bcc"] = ", ".join(message.bcc) |
| 38 | |
| 39 | msg.attach(MIMEText(message.body, message.body_type)) |
| 40 | |
| 41 | if message.attachments: |
| 42 | for file_path in message.attachments: |
| 43 | file = Path(file_path) |
| 44 | if not file.exists(): |
| 45 | raise NotFoundException( |
| 46 | error_no=ErrorNo.EMAIL_ATTACHMENT_NOT_FOUND, message=f"File not found: {file_path}" |
| 47 | ) |
| 48 | msg.attach(EmailService._attach_file(file)) |
| 49 | |
| 50 | self._send_message(msg, message.to) |
| 51 | |
| 52 | @staticmethod |
| 53 | def _attach_file(file_path: Path) -> MIMEBase: |
no test coverage detected