Exemplo n.º 1
0
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)
Exemplo n.º 2
0
 def send_vaccine_notification_by_mail(self, body):
     sender = config.get('mail', 'sender')
     receivers = config.get('mail', 'receivers')
     if self.district is not None:
         subject = "CoWin Vaccine Available in {}".format(self.district)
     elif self.pincode is not None:
         subject = "CoWin Vaccine Available in {}".format(self.pincode)
     else:
         subject = "CoWin Vaccine Available"
     email_client = Mail()
     email_client.connect()
     logging.info("Connected to mail client")
     email_client.send_mail(sender, receivers, subject, body)
Exemplo n.º 3
0

shutil.rmtree('.\\result\\')
sch()

user = your_pw.user
passwd = your_pw.password
regex = re.compile(
    """(https?:\/\/).?(bitly.kr)\/([a-zA-Z0-9]{4})|(https?:\/\/).?(bit.ly)\/([a-zA-Z0-9]{7})|(https?:\/\/).?(goo.gl)\/([a-zA-Z0-9]{6})|(https?:\/\/).?(me2.do)\/([a-zA-Z0-9]{8})|(https?:\/\/).?(grep.kr)\/([a-zA-Z0-9]{4})|(https?:\/\/).?(hoy.kr)\/([a-zA-Z0-9]{4})"""
)

host = user.split('@')[1].split('.')[0]
#print host

mymail = Mail(host, 'imap')
mymail.connect()
mymail.login(user, passwd)
mymail.inbox()
mails = mymail.search(sender='*****@*****.**')
#mymail.logout()

#print mails
shorturl_list = []
datat = []
data = []

for mm in mails:
    mm.fetch()
    #print mm.body
    #print mm.headers["Date"]
    date = mm.headers["Date"]