Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.header import Header
- from email.utils import formataddr
- # Import TEXT only File as Body
- t = open('textmsg.txt', 'r')
- tmsgfile = t.read()
- # Import HTML only File as Body
- h = open('htmlmsg.txt', 'r')
- hmsgfile = h.read()
- # Import E-Mail addresses from file. Separate mail@ddress per line
- addr_f = open('mails.txt', 'r')
- addr_list = []
- for line in addr_f:
- addr_list.append(str((line).replace("\n","")))
- #addr_list.sort()
- print addr_list
- print "\nE-Mails count : ", len(addr_list)
- # Pick Up email recipient from list and send email to address
- counter = 1
- for mail in addr_list:
- from_mail = formataddr((str(Header('www.mysite.sk', 'utf-8')), 'info@mysite.sk'))
- to_mail = mail
- msg = MIMEMultipart('alternative')
- msg['Content-Type'] = "text/html; charset=utf-8"
- msg['Subject'] = Header('MySubject', 'utf-8')
- msg['From'] = from_mail
- msg['To'] = to_mail
- text = tmsgfile
- html = hmsgfile
- part1 = MIMEText(text, 'plain', "utf-8")
- part2 = MIMEText(html, 'html', "utf-8")
- msg.attach(part1)
- msg.attach(part2)
- s = smtplib.SMTP('smtp.server.sk:25')
- s.starttls()
- s.login('info@mysite.sk','MyPass')
- s.sendmail(from_mail, to_mail, msg.as_string())
- print "\n", counter, "Message sent to :", mail
- counter += 1
- s.quit()
- print "\nFinish"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement