def send_email(msg_content):
global emailinfo
try:
# Try to login smtp server
s = smtplib.SMTP("smtp.gmail.com:587")
s.ehlo()
s.starttls()
s.login(emailinfo['sender'], emailinfo['sender-password'])
except smtplib.SMTPAuthenticationError:
# Log in failed
print smtplib.SMTPAuthenticationError
print('[Mail]\tFailed to login')
else:
# Log in successfully
print('[Mail]\tLogged in! Composing message..')
for receiver in emailinfo['receivers']:
msg = MIMEMultipart('alternative')
msg['Subject'] = msg_content['Subject']
msg['From'] = emailinfo['sender']
msg['To'] = receiver
text = msg_content['Content']
part = MIMEText(text, 'plain')
msg.attach(part)
s.sendmail(emailinfo['sender'], receiver, msg.as_string())
print('[Mail]\tMessage has been sent to %s.' % (receiver))
# send notified mail once a day.
评论列表
文章目录