title: Replace body message of an email using python
body: <p>I created a class in python that will send emails via one of my private servers.  It works but I'm wondering if there is a method to replace an existing email body message with a new one?</p>
  
  <p><strong>Emailer Class</strong></p>
  
  <pre><code>class Emailer:
  
    def __init__(self, subj=None, message=None, toAddr=None, attachment=None, image=None):
      # initialize email inputs
  
      self.msg = email.MIMEMultipart.MIMEMultipart()
  
      self.cidNum = 0
  
      self.message = []
      if message is not None:
          self.addToMessage(message,image)
  
      # set the subject of the email if there is one specified
      self.subj = []
      if subj is not None:
          self.setSubject(subj)
  
      # set the body of the email and any attachements specified
      self.attachment = []
      if attachment is not None:
          self.addAtachment(attachment)
  
      # set the recipient list
      self.toAddr = []
      if toAddr is not None:
          self.addRecipient(toAddr)
  
    def addAttachment(self,attachment):
      logger.debug("Adding attachement to email")
      # loop through list of attachments and add them to the email
      if attachment is not None:
          if type(attachment) is not list:
              attachment = [attachment]
          for f in attachment:
              part = email.MIMEBase.MIMEBase('application',"octet-stream")
              part.set_payload( open(f,"rb").read() )
              encoders.encode_base64(part)
              part.add_header('Content-Disposition', 'attachment; filename="{0}"'.format(os.path.basename(f)))
              self.msg.attach(part)
  
    def addToMessage(self,message,image=None):
      logger.debug("Adding to email message. Content: [%s]" % message)
      # add the plain text message
      self.message.append(message) 
      # add embedded images to message
      if image is not None:
          if type(image) is not list:
              image = [image]
          for i in image:
              msgText = email.MIMEText.MIMEText('&lt;br&gt;&lt;img src="cid:image%s"&gt;&lt;br&gt;' % self.cidNum, 'html')   
              self.msg.attach(msgText)
  
              fp = open(i, 'rb')
              img = email.MIMEImage.MIMEImage(fp.read())
              fp.close()
              img.add_header('Content-ID','&lt;image%s&gt;' % self.cidNum)
              self.msg.attach(img)
              self.cidNum += 1
  
  # method to set the subject of the email
    def setSubject(self,subj):
      self.msg['Subject'] = subj
  
  # method to add recipients to the email
    def addRecipient(self, toAddr):
      # loop through recipient list
      for x in toAddr:
          self.msg['To'] = x
  
  # method to configure server settings: the server host/port and the senders login info
    def configure(self,  serverLogin, serverPassword, fromAddr, toAddr, serverHost='myserver', serverPort=465):
      self.server=smtplib.SMTP_SSL(serverHost,serverPort) 
      self.server.set_debuglevel(True)
      # self.server.ehlo()
      # self.server.ehlo()
      self.server.login(serverLogin, serverPassword)  #login to senders email
      self.fromAddr = fromAddr
      self.toAddr = toAddr
  
  # method to send the email
    def send(self):
      logger.debug("Sending email!")
      msgText = email.MIMEText.MIMEText("\n".join(self.message))
      self.msg.attach(msgText) 
      print "Sending email to %s " % self.toAddr
      text = self.msg.as_string() #conver the message contents to string format
      try:
          self.server.sendmail(self.fromAddr, self.toAddr, text)  #send the email
      except Exception as e:
          logger.error(e)
  </code></pre>
  
  <p>Currently, the <code>addToMessage()</code> method is what adds text to the body of the email.   If <code>addToMessage()</code> had already been called but I wanted to replace that body text with new text, is there a way?</p>