当前位置: 首页>>代码示例>>Python>>正文


Python Mail.test_connection方法代码示例

本文整理汇总了Python中mail.Mail.test_connection方法的典型用法代码示例。如果您正苦于以下问题:Python Mail.test_connection方法的具体用法?Python Mail.test_connection怎么用?Python Mail.test_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mail.Mail的用法示例。


在下文中一共展示了Mail.test_connection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from mail import Mail [as 别名]
# 或者: from mail.Mail import test_connection [as 别名]
class Message:


    def __init__(self):
        self.__LOG_TAG__ = "MESSAGE"

        self.__mail = Mail(self.__read_mail_values())
        self.__whatsapp = WhatsApp()

    def __read_mail_values(self):
        """Read e-mail values in xml configuration file"""

        tree = xml.dom.minidom.parse("../config.xml")
        config = tree.getElementsByTagName('config')[0]
        msg_config = config.getElementsByTagName('msg_config')[0]
        l_email = msg_config.getElementsByTagName('email')[0]

        l_description = l_email.getAttribute('description')
        l_host = l_email.getAttribute('host')
        l_port = int(l_email.getAttribute('port'))
        l_login = l_email.getAttribute('login')
        l_password = l_email.getAttribute('password')
        l_sender = l_email.getAttribute('sender')
        l_target = l_email.getAttribute('target') #for tests. later can be any user's email
        l_complete = True

        log.info(self.__LOG_TAG__, "Infos of e-mail read [%s]" %l_sender)

        return l_description, l_host, l_port, l_login, l_password, l_sender, l_target, l_complete

    def is_connected_mail(self):
        """Check if email server is connected"""

        return self.__mail.is_connected()

    def connect_mail(self):
        """Connect to email server."""

        self.__mail.connect();

    def test_connection_mail(self):
        """Try to reconnect to the server if it is not connected."""
        
        self.__mail.test_connection()

    def disconnect_mail(self):
        """Disconnecd from email server"""

        self.__mail.disconnect()

    def send_mail(self, p_target, p_subject="[no_subject]", p_msg="Hello!"):
        """send one or more emails
        target: str, list or tuple
        """

        self.__mail.send(p_target, p_subject, p_msg)
开发者ID:guikingma,项目名称:Jarbas,代码行数:58,代码来源:message.py


注:本文中的mail.Mail.test_connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。