1. 只需3行代码发带附件的邮件
注意:yagmail库需要自己用pip命令安装:
pip3 install yagmail
利用163邮箱,需要在设置中打开pop3,并设置授权码,作为password,否则python作为第三方客户端是无法发送邮件的。
# 前提是需要拿到发邮件的邮箱的POP3授权码,作为password,而非邮箱密码
import yagmail
yag = yagmail.SMTP( user="[email protected]", password="123456", host='smtp.163.com')
yag.send('[email protected]', '标题', '正文',['1.jpg','2.jpg'])
2. 自动替换朋友圈截图头像【博主原创,欢迎转载】
其实昵称也可以自动替换。1:根据分割线定位头像,2:根据头像位置定位昵称位置,3:用背景色抹掉昵称区域,,4:使用ImageDraw库调用指定字体绘制文字
# 根据微信朋友圈内容灰色的分割线自动定位头像位置 Success
# 需手动根据截图设置2个参数:1朋友圈截图的顶部高度2头像的宽高
from PIL import Image, ImageDraw, ImageFont
image=Image.open('pyq.jpg') # 截图需刚好漏出朋友圈内容分割线-那条灰色横线
# 探测朋友圈内容分割线,定位头像
# 分割线颜色 (229,229,229)
lineRGB = (229,229,229) # 灰色朋友圈内容分割线颜色
pyqTopY = 257 #朋友圈截图的标题栏高度
iconX = 30 #扫描区域左边界
scan = (iconX,pyqTopY,iconX+1,550) #扫描区 1像素宽,高度从内容区顶部到底部
zone = image.crop(scan)
lineY = 0
for y in range(zone.size[1]):
rgb = zone.getpixel((0,y))
if rgb[0] == lineRGB[0] and rgb[1] == lineRGB[1] and rgb[2] == lineRGB[2] :
lineY = y + box[1]
break
print(lineY)
# 头像y
iconboxY = lineY + 45
iconboxX = 44
iconw, iconh = 143,143 #头像宽高需根据不同分辨率截图设置
iconbox = (iconboxX, iconboxY, iconboxX + iconw, iconboxY + iconh)
icon = Image.open('tx.jpg') # 新头像图片
image.paste(icon, iconbox)
outimg = 'output.jpg'
image.save(outimg, 'JPEG', quality = 100)