Python Implementation Payroll Script

Source: Internet
Author: User
Tags python script

Tag: Deb succeeded. Text Context set INF tab TAC ATT

Good happy ah, next to the help of the great God, finally realized the wages of the Python script, before using the shell to write the old error, just test, send 80 people pay details, duly completed, the code is as follows:

From Email.mime.multipart import mimemultipartfrom email.mime.text import mimetextfrom email.mime.image Import Mimeimagefrom email.header Import header#from handle_data_for_salary import Main#import handle_data_for_salaryimport        Smtplibimport xlrdimport xdrlib,sysdef open_excel (file= ' Test1.xls '): Try:data = Xlrd.open_workbook (file) Return data except Exception as E:print (str (e)) def excel_table_byname (file= ' Test1.xls ', colnameindex=0,by_name= ' Sheet1 '): data = open_excel (file) Table = Data.sheet_by_name (by_name) nrows = table.nrows #行数 colnames = tabl        E.row_values (colnameindex) #某一行数据 list = [] for rownum in range (2,nrows): row = Table.row_values (rownum)            If Row:app = {} for I in range (len (colnames)): app[colnames[i]] = Row[i] List.append (APP) return Listdef get_value (): tables = Excel_table_byname () for row in Tables:globa    L Mail mail = row["email address"]        Global name name = row["Name"] Global context AuthInfo = {} authinfo[' SE            RVer '] = ' smtp.163.com ' authinfo[' user '] = ' [email protected] ' authinfo[' password '] = ' email password '            Fromadd = ' [email protected] ' subject = ' email subject ' context = str (row) Toadd = [Mail,] SendEmail (AuthInfo, Fromadd, Toadd, subject, context) def sendEmail (AuthInfo, Fromadd, Toadd, S Ubject, plaintext): Strfrom = Fromadd Strto = '; '. Join (toadd) server = authinfo.get (' server ') Smtpport = Sslport = 465 user = Authinfo.get ( ' user ') passwd = authinfo.get (' password ') if not (server and user and passwd): Print (' Incomp Lete Login info, exit now ') return # set root information Msgroot = Mimemultipart (' related ') Msgro ot[' Subject ' = Subject msgroot[' from '] = '%s<%s> ' (Header (' Payroll details ', 'Utf-8 '), strfrom) msgroot[' to ' = strto # message body Content Msgtext = Mimetext (plaintext, ' plain ', ' utf-8 ')        Msgroot.attach (msgtext) msgalternative = Mimemultipart (' alternative ') Msgroot.attach (msgalternative) Try: #发送邮件 smtp = Smtplib. SMTP () smtp.connect (server, Smtpport) #ssl加密方式, communication process encryption, message data security # SMTP = Smtplib . Smtp_ssl () # smtp.connect (server, Sslport) #设定调试级别, depending on the situation # Smtp.set_debugleve                L (1) smtp.login (user, passwd) smtp.sendmail (Strfrom, Toadd, msgroot.as_string ()) Smtp.quit () print ("message sent to%s succeeded!"% (         name)) except Exception as E:print ("failure:" + str (e)) if __name__ = = ' __main__ ': Get_value ()

Note: The python environment is 3.5, the lab environment is in Windows, using the tool for Pycharm, the module that needs to be used: PIP3 install XLRD, where the payroll table, as shown in the section: There are a lot of columns behind, to see their needs add no, anyway, is a column of data

The experimental results are as follows:

Now just to achieve the demand, sent more than estimated the e-mail problem, and the format of the mail is too ugly, and so on home to change, refueling

Python Implementation Payroll Script

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.