smtplib_email邮件、itches微信和twilio短信

上一篇Python群发个性化邮件的视频链接整错了,给整到Python发邮件上去了。另外给女神们群发的邮件里可以加一张女神的照片,前提是您能确保不会把照片弄错,可千万别像我这样!

气人的是发之前我还检查来着,结果还是把两个整到一个去了。

赶紧道歉&更正!

为了继续隐瞒我非常粗心毛躁的事实,决定分享个不知道哪看来的&我特有共鸣的段子:

有个黑人小哥在Facebook上吐槽,大意是“你们有没有这样的经历,你问女朋友XXX在哪里,女朋友说在架子上。然后你走到架子前上看下看左看右看,断定你要找的东西根!本!就!不!在!那!儿!

可她非坚持东西就在那儿”

......

一帮人应和

…...
然后他又写到“后来你女朋友走过来,不耐烦滴用手一指,然后不可思议的事情发生了,那个你要找的东西它竟然...竟然...真滴出现啦!!!”

(旁白:嗯,同意他女朋友的手指有神奇魔力)

应和的人比刚才更多了。

我在发送上一篇帖子前,仔仔细细检查过没链接到一个视频上。临发前我还特意又读了一遍......没看出它是链接到一个视频上啊。

真邪门,那群发邮件的视频啥时候连去发送邮件的视频上的呀?

明明我检查过了呀!简直了!谁干的!敢不敢站出来?

除了我没别人,不敢相信是我干的

抱歉

传上个视频到网易云课堂,连了一上午,上传很费劲。总断线,战战兢兢滴怕断线后再也连不上。今天电脑是压根连不上,所以没法看网易云课堂上的问题,更没法回复。不知是我这边的问题还是哪里的问题。

Python群发个性化邮件:

 

# # http://blog.csdn.net/zl87758539/article/details/53363860
#
from email.mime.text import MIMEText
import smtplib
#
mailto_list = ["This email address is being protected from spambots. You need JavaScript enabled to view it.","This email address is being protected from spambots. You need JavaScript enabled to view it."]
#
mail_host = "smtp.qq.com"
mail_user = "pythonabc"
mail_pass = "xuapwdrgxocnddec"
#
#==========================================
# 发送邮件
#==========================================
def send_mail(to_list, sub, content):
  '''''
  to_list:发给谁
  sub:主题
  content:内容
  send_mail("This email address is being protected from spambots. You need JavaScript enabled to view it.","主题","内容")
  '''
#
  msg = MIMEText(content)
  msg['Subject'] = sub
  msg['From'] = This email address is being protected from spambots. You need JavaScript enabled to view it.'
  msg['To'] = ";".join(to_list)
#
  try:
    s = smtplib.SMTP_SSL(mail_host, 465)
    # s.set_debuglevel(1)
    s.login(mail_user,mail_pass)
    s.send_message(msg)
    s.close()
    return True
#
  except Exception as e:
    print(e)
    return False
#
if send_mail(mailto_list,"群发邮件","试试可不可以"):
    print("发送成功")
else:
    print("发送失败")




# https://medium.freecodecamp.org/send-emails-using-code-4fcea9df63f
#
MY_ADDRESS = This email address is being protected from spambots. You need JavaScript enabled to view it.'
MY_PASSWORD = 'xuapwdrgxocnddec'
#
# Function to read the contacts from a given contact file and return a
# list of names and email addresses
# {'青霞', '曼玉'}
# {This email address is being protected from spambots. You need JavaScript enabled to view it.', This email address is being protected from spambots. You need JavaScript enabled to view it.'}
def get_contacts(filename):
    names = []
    emails = []
    with open(filename, mode='r', encoding='utf-8') as contacts_file:
        for a_contact in contacts_file:
            names.append(a_contact.split()[0])
            emails.append(a_contact.split()[1])
    return names, emails
#
# to read in a template file (like message.txt) and return a Template object
# made from its contents
from string import Template
#
def read_template(filename):
    with open(filename, 'r', encoding='utf-8') as template_file:
        template_file_content = template_file.read()
    return Template(template_file_content)
#
#
# import the smtplib module. It should be included in Python by default
import smtplib
#
# set up the SMTP server
s = smtplib.SMTP_SSL(host='smtp.qq.com', port=465)
# # outlook: s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587)
# # Gmail: smtp.gmail.com:port (TLS): 587;port (SSL): 465.
#
s.login(MY_ADDRESS, MY_PASSWORD)
#
# to fetch the contact information and the message templates
names, emails = get_contacts('mycontacts.txt')  # read contacts
message_template = read_template('message.txt')
#
#
# send the mail separately
#
# import necessary packages
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
#
# For each contact, send the email:
for name, email in zip(names, emails):
    msg = MIMEMultipart()       # create a message
#
    # add in the actual person name to the message template
#
    message = message_template.safe_substitute(PERSON_NAME=name.title())
#
    # setup the parameters of the message
    msg['From'] = MY_ADDRESS
    msg['To'] = email
    msg['Subject'] = "你是人间的四月天"
#
    # add in the message body
    msg.attach(MIMEText(message, 'plain'))  # send the message via the server set up earlier.
    s.send_message(msg)
#
    del msg
#
# Terminate the SMTP session and close the connection
s.quit()