# Path: fooltrader/settings.py
# SMTP_HOST = 'smtpdm.aliyun.com'
# 
# SMTP_PORT = '80'
# 
# EMAIL_PASSWORD = ''
# 
# EMAIL_USER_NAME = ''
# 
# WEIXIN_APP_ID = ""
# 
# WEIXIN_APP_SECRECT = ""


import email
import json
import logging
import smtplib
import requests
import schedule
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from fooltrader.settings import SMTP_HOST, SMTP_PORT, EMAIL_PASSWORD, EMAIL_USER_NAME, WEIXIN_APP_ID, WEIXIN_APP_SECRECT



class Action(object):
    logger = logging.getLogger(__name__)

    def send_message(self, to_user, title, body, **kwargs):
        pass


class EmailAction(Action):
    def __init__(self) -> None:
        super().__init__()

    def send_message(self, to_user, title, body, **kwargs):
        smtp_client = smtplib.SMTP()
        smtp_client.connect(SMTP_HOST, SMTP_PORT)
        smtp_client.login(EMAIL_USER_NAME, EMAIL_PASSWORD)
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('fooltrader').encode(), EMAIL_USER_NAME)
        msg['To'] = to_user

        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:

# Path: fooltrader/settings.py
# SMTP_HOST = 'smtpdm.aliyun.com'
# 
# SMTP_PORT = '80'
# 
# EMAIL_PASSWORD = ''
# 
# EMAIL_USER_NAME = ''
# 
# WEIXIN_APP_ID = ""
# 
# WEIXIN_APP_SECRECT = ""


# Path: fooltrader/bot/action/msg_action.py
import email
import json
import logging
import smtplib
import requests
import schedule
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from fooltrader.settings import SMTP_HOST, SMTP_PORT, EMAIL_PASSWORD, EMAIL_USER_NAME, WEIXIN_APP_ID, WEIXIN_APP_SECRECT




class Action(object):
    logger = logging.getLogger(__name__)

    def send_message(self, to_user, title, body, **kwargs):
        pass


class EmailAction(Action):
    def __init__(self) -> None:
        super().__init__()

    def send_message(self, to_user, title, body, **kwargs):
        smtp_client = smtplib.SMTP()
        smtp_client.connect(SMTP_HOST, SMTP_PORT)
        smtp_client.login(EMAIL_USER_NAME, EMAIL_PASSWORD)
        msg = MIMEMultipart('alternative')
        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('fooltrader').encode(), EMAIL_USER_NAME)
        msg['To'] = to_user

        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:

            smtp_client.sendmail(EMAIL_USER_NAME, to_user, msg.as_string())