Recently i've been doing ubuntu tutorials.This is the odd one.
I've got a forwarded mail which has lot of emails.I thought of promoting my blog.It's tedious to type all those emails or removing extra characters.
With this you can forward emails faster and people will really read it.
import smtplib
import email
from email.MIMEMultipart import MIMEMultipart
from email.parser import Parser
from email.MIMEText import MIMEText
import mimetypes
s='"xxx@yyy.com"<xxx@yyy.com>,"xxx@yyy.com"<xxx@yyy.com>'
# ==> s='Insert the copied email ids between ' single quotes''
email_id_array=[]
old_lts=0
old_gts=0
#lts,gts==> less than sign, greater than sign
while old_lts!=-1:
lts=s.find('<',old_lts+1)
gts=s.find('>',old_gts+1)
email_id=s[lts+1:gts]
print email_id
email_id_array.append(email_id)
old_lts=lts
old_gts=gts
email_id_array.pop()
print email_id_array
with open('C:\Documents and Settings\Ajay\Desktop\emails.txt','w') as f:
#C:\Documents and Settings\Ajay\Desktop\emails.txt ==> change this to appropriate location
for i in range(len(email_id_array)):
f.write(email_id_array[i]+','+"\n")
"""Some part of this was taken from
http://jayrambhia.com/blog/send-emails-using-python/
this blog.
you can add atatchments aswell
"""
server = smtplib.SMTP()
server.connect('smtp.gmail.com', 587) # for eg. host = 'smtp.gmail.com', port = 587
server.ehlo()
server.starttls()
server.login('your gmail id', 'your secret password')
#username@gmail.com
#Enter your password.
fromaddr ='your gmail id'
for i in range(len(email_id_array)-1):
msg = email.MIMEMultipart.MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = email_id_array[i]
msg['Subject'] = 'Testing...'
msg.attach(MIMEText('Very Important..'))
msg.attach(MIMEText('WEFORCHRIST has crossed 1900+ fans on facebook.Join us @ www.facebook.com/weforchrist.Hope you like our page.', 'plain')) # just a way to say.. Ha! I use Python.
server.sendmail(fromaddr,email_id_array[i],msg.as_string())
server.quit()
your gmail id and password should be given, rest the same...
Copy the above script and give it a name.Start python interpreter and run this module.If your from Linux i need not explain anything.
If you don't have python download from Python official website
1.Download and install python
2.Get the email ids from any forwarded message.
3.save the above python script and run the module
4. Success...Your message is sent.
Learn python for fun.The popular blog with questions and answers to the python.Solutions to facebookhackercup,codejam,codechef.The fun way to learn python with me.Building some cool apps.


Sending bulk emails is good especially if the contents are informative and not spammy.
ReplyDelete