КАК БЫСТРО рассылать почту с Python
EASY send email with Python
vim /tmp/send_mail.py
from base64 import b64decode
import requests
import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
import re
def send_mail(files=None, notification=""):
sender_address = 'one_gmail@gmail.com'
sender_pass = 'aklshdlaaklsjd'
receiver_address = ["one_gmail@gmail.com", "two_gmail@gmail.com"]
mail_content = notification + "\n" + '''See attachements
&
&&/ ##(&%
#((&&&/((&&
&/(#&&/((((&(
&///&//((((#&&%
&//((((((((((((&(/&
&/(/%(((((((((((((&((/&
&//(/&&. &(((((((((((((((/&/
&//((/& &((((((&&%(((&#&&&
&//(((/& &((((((&(((((((&&&(///&
&//((((((((((((((((((&&((((((((((&&&&&&
,%//(((((((((((((((((((((&/(((((((((&#((&%
&//(((((((((((((((((((&&&&&&/((((((((&((%@
&/(%&&(((((((((((((((&& &/((((((&(
&/((&(((((((((((((((&& &&((((((((&&
&(((((((((((((&&&&&& &///(((((&&
&((((((((((&&&&& &&/(((((&&
&&#((((&&& &//((((&&&
&&&/(((((&&
&&&&/
'''
msg = MIMEMultipart()
msg['From'] = sender_address
msg['To'] = ", ".join(receiver_address)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = 'Notification from server'
msg.attach(MIMEText(mail_content, 'plain'))
for f in files or []:
with open(f, "rb") as fil:
part = MIMEApplication(
fil.read(),
Name=basename(f)
)
# After the file is closed
part['Content-Disposition'] = 'attachment; filename="%s"' % basename(f)
msg.attach(part)
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls() #enable security
session.login(sender_address, sender_pass) #login with mail_id and password
text = msg.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
print('Mail Sent')
send_mail(["/Users/dmitry/Downloads/11111.png"], "Privet")
python3 /tmp/send_mail.py
Read other posts