1. import configparser
    2. from utils.logger import log
    3. class MailConf:
    4. def __init__(self):
    5. conf = configparser.ConfigParser()
    6. conf.read("..\\config\\mail.conf", encoding="utf-8")
    7. # 读取邮件服务器地址
    8. self.mail_host = conf.get("mail", "mail_host")
    9. # print(self.mail_host)
    10. # 读取邮件服务器端口
    11. self.mail_port = conf.get("mail", "mail_port")
    12. # print(self.mail_port)
    13. # 读取发件人邮箱地址
    14. self.mail_username = conf.get("mail", "mail_username")
    15. # print(self.mail_username)
    16. # 读取发件人邮箱授权码
    17. self.mail_password = conf.get("mail", "mail_password")
    18. # print(self.mail_password)
    19. # 读取收件人邮箱地址
    20. self.receivers = conf.get("mail", "receivers")
    21. # print(self.receivers)
    22. # 读取抄送人邮箱地址
    23. self.cc = conf.get("mail", "cc")
    24. # print(self.cc)
    25. def get_mail_host(self):
    26. log.info(f"邮箱服务器地址是:{self.mail_host}")
    27. return self.mail_host
    28. def get_mail_port(self):
    29. log.info(f"邮箱服务器端口是:{self.mail_port}")
    30. return self.mail_port
    31. def get_mail_username(self):
    32. log.info(f"发件人邮箱地址是:{self.mail_username}")
    33. return self.mail_username
    34. def get_mail_password(self):
    35. # 不建议把授权码打印到日志,因为要密码
    36. return self.mail_password
    37. def get_receivers(self):
    38. log.info(f"收件人邮箱地址是{self.receivers}")
    39. return self.receivers
    40. def get_cc(self):
    41. log.info(f"抄送人邮箱地址是{self.cc}")
    42. return self.cc
    43. if __name__ == '__main__':
    44. print(MailConf().get_mail_host())
    45. print(MailConf().get_mail_port())
    46. print(MailConf().get_mail_username())
    47. print(MailConf().get_mail_password())
    48. print(MailConf().get_receivers())
    49. print(MailConf().get_cc())