前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 给没有交会费的会员发邮件 脚本

python 给没有交会费的会员发邮件 脚本

作者头像
用户5760343
发布2022-05-13 18:01:46
3030
发布2022-05-13 18:01:46
举报
文章被收录于专栏:sktj

! python3

sendDuesReminders.py - Sends emails based on their status in spreadsheet.

import openpyxl, smtplib, sys

Open the spreadsheet and get the latest dues status.

wb = openpyxl.load_workbook('duesRecords.xlsx') sheet = wb.get_sheet_by_name('Sheet1')

lastCol = sheet.get_highest_column() latestMonth = sheet.cell(row=1, column=lastCol).value

unpaidMembers = {}

Check each member's payment status

for r in range(2, sheet.get_highest_row() + 1): payment = sheet.cell(row=r, column=lastCol).value if payment != 'paid': name = sheet.cell(row=r, column=1).value email = sheet.cell(row=r, column=2).value unpaidMembers[name] = email

Log in to email account.

smtpObj = smtplib.SMTP('smtp.gmail.com', 587) smtpObj.ehlo() smtpObj.starttls() smtpObj.login('my_email_address@gmail.com', sys.argv[1])

Send out reminder emails.

for name, email in unpaidMembers.items(): body = 'Subject: %s dues unpaid.\nDear %s,\nRecords show that you have not paid dues for %s. Please make this payment as soon as possible. Thank you!' % (latestMonth, name, latestMonth) print('Sending email to %s...' % email) sendmailStatus = smtpObj.sendmail('my_email_address@gmail.com', email, body)

代码语言:javascript
复制
if sendmailStatus != {}:
    print('There was a problem sending email to %s: %s' % (email, sendmailStatus))

smtpObj.quit()

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ! python3
  • sendDuesReminders.py - Sends emails based on their status in spreadsheet.
  • Open the spreadsheet and get the latest dues status.
  • Check each member's payment status
  • Log in to email account.
  • Send out reminder emails.
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档