Python implements email notification for user login, and python email notification

Source: Internet
Author: User

Python implements email notification for user login, and python email notification

The example in this article describes how to implement email notification for user login in python. Share it with you for your reference. The details are as follows:

This is scheduled to run in a scheduled task in linux. When a new user logs in, the user name is sent to the specified email address to notify the administrator.

#! /Usr/bin/env python # encoding = utf-8from smtplib import SMTPimport subprocesssmtp = "smtp.qq.com" user = '000000' password = 'xxxx' run _ comd = subprocess. popen ('W packet grep pts ', shell = True, stdout = subprocess. PIPE) data = run_comd.stdout.read () mailb = ["the server has a new user login", data] mailh = ["From: 1234567@qq.com", "To: xxxx@gmail.com", "Subject: user Logon monitoring "] mailmsg =" \ r \ n ". join (["\ r \ n ". join (mailh), "\ r \ n ". join (mailb)]) def send_mail (): send = SMTP (smtp) send. login (user, password) result = send. sendmail ("1234567@qq.com", ("xxxx@gmail.com",), mailmsg) send. quit () if data = '': passelse: send_mail ()

I hope this article will help you with Python programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.