473,574 Members | 5,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding sender name to email

How do I add a Sender name to the emails sent by the following script:

def createhtmlmail (html, text, subject):
"""Create a mime-message that will render HTML in popular
MUAs, text in better ones"""
import MimeWriter
import mimetools
import cStringIO

out = cStringIO.Strin gIO() # output buffer for our message
htmlin = cStringIO.Strin gIO(html)
txtin = cStringIO.Strin gIO(text)

writer = MimeWriter.Mime Writer(out)
# set up some basic headers... we put subject here
# because smtplib.sendmai l expects it to be in the
# message body
#
writer.addheade r("Subject", subject)
writer.addheade r("MIME-Version", "1.0")
#
# start the multipart section of the message
# multipart/alternative seems to work better
# on some MUAs than multipart/mixed
#
writer.startmul tipartbody("alt ernative")
writer.flushhea ders()
#
# the plain text section
#
subpart = writer.nextpart ()
subpart.addhead er("Content-Transfer-Encoding", "quoted-printable")
pout = subpart.startbo dy("text/plain", [("charset", 'us-ascii')])
mimetools.encod e(txtin, pout, 'quoted-printable')
txtin.close()
#
# start the html subpart of the message
#
subpart = writer.nextpart ()
subpart.addhead er("Content-Transfer-Encoding", "quoted-printable")
#
# returns us a file-ish object we can write to
#
pout = subpart.startbo dy("text/html", [("charset", 'us-ascii')])
mimetools.encod e(htmlin, pout, 'quoted-printable')
htmlin.close()
#
# Now that we're done, close our writer and
# return the message body
#
writer.lastpart ()
msg = out.getvalue()
out.close()
return msg

if __name__=="__ma in__":
import smtplib
from time import *

f = open("mssg.html ", 'r')
html = f.read()
f.close()
f = open("mssg.txt" , 'r')
text = f.read()
f.close()
subject = "subject)"

f = open("temp.txt" , 'r')
RECIPIENTS = []
for line in f:
RECIPIENTS.appe nd(line.strip() )
f.close()
for i in RECIPIENTS:
if len(i) == 0:
RECIPIENTS.remo ve(i)
print "Number of recipients: ", len(RECIPIENTS)

SENDER = 'm***@mail.com'
print "Generating message..."
mssg = createhtmlmail( html, text, subject)
print "Opening session"
session = smtplib.SMTP("l ocalhost")
print "Sending email"
offset = 0
blocksize = 20 # to send emails in blocks of 20, so I don't
bomb out my server
while offset*blocksiz e < len(RECIPIENTS) :
print "Sending message ", offset*blocksiz e, " - ",
(offset+1)*bloc ksize, "of ", len(RECIPIENTS) , "..."
smtpresult =
session.sendmai l(SENDER,RECIPI ENTS[offset*blocksiz e:(offset+1)*bl ocksize],mssg)
sleep(30)
offset += 1
## smtpresult = session.sendmai l(SENDER, RECIPIENTS, mssg)

if smtpresult:
errstr = ""
for recip in smtpresult.keys ():
errstr = """Could not delivery mail to: %s
Server said: %s
%s
%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
raise smtplib.SMTPExc eption, errstr
session.quit()

Sep 1 '06 #1
0 1736

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1346
by: serge calderara | last post by:
Dear all, I have an application which timely create log file in XML format I ma using the SystemFileWatcher object to monitor creation of new file in the proper path. So far no problem When the first file is created, my SystemFile onchanged event is catch and then I add the new log file in a treview control with the following code: Dim...
0
3117
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the full code for the test below. Create a project drop in the code and run. Any help would be appreciated. Cheers,
3
4866
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
1
2025
by: seanmayhew | last post by:
I have a form page that that while editing saves the data to an xml doc before submitting to db. On each page unload it saves the xmldoc as the user can add multiple items to the company like product types etc. So for instance Im adding a fruit company while adding a fruit company I allow the user to add types of fruit they carry and...
3
2334
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example...
1
4223
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn...
1
1435
by: Manuel Canas | last post by:
Hey guys, This code was posted by Cor Ligther some rows below here. hey bud if you read this one can you help me out here or anybody that know the answer to this one. How would I add a second table to this DataSet? Thanks Guys.
3
4612
by: mcse4u | last post by:
I would like to be able to add a hyperlink to the posted form below that automatically creates a hyperlink of the email address of the person submitting the form. Can someone please help me with the code I need to add? <%@language=vbscript%> <%option explicit dim fromMail
2
7652
by: Ken Fine | last post by:
I want to add the security question and answer security feature to the ChangePassword control. I am aware that this functionality is built into the PasswordRecovery tool. I have implemented the PasswordRecovery with a Password reset required; a temporary password is sent to the account on file. I want an extra layer of security to accommodate...
0
7826
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8126
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5637
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1090
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.