Last active
July 23, 2018 13:08
-
-
Save pypeach/6c2a9db6e3770283fd351db74efbc492 to your computer and use it in GitHub Desktop.
メール送信を行うサンプルアプリケーションです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
import logging | |
from app.app_logic_base import AppLogicBase | |
from app.util import message_access, app_config, mail_sender | |
""" | |
メール送信するサンプルアプリケーションです | |
""" | |
__author__ = "t.ebinuma" | |
__version__ = "1.0" | |
__date__ = "18 March 2018" | |
class SendMail(AppLogicBase): | |
def __init__(self): | |
super().__init__() | |
# loggerを設定する | |
self.logger = logging.getLogger(__name__) | |
def send_mail(self): | |
""" | |
メール送信を行う | |
""" | |
try: | |
# Fromを設定する | |
mail_from = app_config.get_value("mail_from") | |
# Toを設定する(複数設定も可能です) | |
mail_to_list = [app_config.get_value("mail_to")] | |
# 件名を設定する | |
mail_subject = 'メール件名です' | |
# 本文を設定する | |
mail_body = mail_sender.get_mail_template_text('sample.txt').replace("{mail_text}", str("メール本文です")) | |
# 添付ファイルパスを設定する(複数設定も可能です) | |
mail_attachment_file = [ | |
app_config.get_data_file_path('attachment_file.txt'), | |
app_config.get_data_file_path('attachment_file.csv'), | |
app_config.get_data_file_path('attachment_file.png') | |
] | |
# メール送信する | |
mail_sender.send(mail_from, mail_to_list, mail_subject, mail_body, mail_attachment_file) | |
except Exception as e: | |
# エラー発生時はメッセージを出力する | |
self.logger.error(message_access.get_message('E902'), e) | |
raise e | |
def main(): | |
sm = SendMail() | |
sm.send_mail() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
親クラスを追加