May 2012
M T W T F S S
« Jul «-»  
 123456
78910111213
14151617181920
21222324252627
28293031  

Leaving Chris World?

Why not bring back a souvenir?

Archives

Inbox Poem Program


Use this at your own risk and with extreme care.
You have the power to spam in a very unappealing way.

Keep your poems short enough to appear in subject lines
It works best when the person is using gmail.
Use only for good... not evil.

 
# Inbox Poem Sender
# Concept by Chris Stones
# welcometochrisworld.com
# March 24, 2009
#
# Fantastic gmail email code by
# http://kutuma.blogspot.com/2007/08/sending-emails-via-gmail-with-python.html
 
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
 
gmail_user = "YOURGMAIL@gmail.com"
gmail_pwd = "YOUR_GMAIL_PASSWORD"
 
def mail(to, subject, text): #, attach):
   msg = MIMEMultipart()
 
   msg['From'] = gmail_user
   msg['To'] = to
   msg['Subject'] = subject
 
   msg.attach(MIMEText(text))
 
   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(gmail_user, gmail_pwd)
   mailServer.sendmail(gmail_user, to, msg.as_string())
   # Should be mailServer.quit(), but that crashes...
   mailServer.close()
 
to_her = "TOHERorHIM@theiraddress.com"
 
# the poem part
# Your poem should be a list of strings
poem = ["Simple to hear",
		"to Listen to touch",
		"But so far away",
		"almost a crutch",
		"still you are here",
		"at home in my heart",
		"and so functionally speaking",
		"we never do part"]
 
# when the e mails are in the inbox they are first line last
# so we send in reverse order
poem.reverse()
 
for line in poem:
	mail(to_her,line,line)
 
#nothing to it
 

5 comments to Inbox Poem Program

  • Hey, Thanks Chris, it works great!

    And to be reasonable about the “spam”, just write haiku :)

  • I’m glad you enjoyed it. And thanks for the comment.

  • What a great idea! I found this post in the comments on the Gmail email code page you cite in your source code (tip of the hat to you, sir). This is really a novel idea; maybe I’ll give this a shot sometime soon. And I like the haiku suggestion, too!

  • A bit of an update. The lines may show up out of order unless you add a considerable pause between sends. This has to do with network latency. And I find it it’s an issue sometimes and sometimes not but it helps to be careful so that your poem has a better chance of not looking like post modern abstract art. Or something.

  • Bit of a note here. You ought to add a considerable pause between sends or the messages might arrive out of order due to network latency issues. It’s not always a huge problem but it pays to be careful so that your poems don’t come out looking like post modern abstract art.

You must be logged in to post a comment.