Issue in Sending email having utf-8 strings in python 2.6
<p>Please find below relevant code snippet :</p>

<pre><code>def send_mail_cloned():
    COMMASPACE = ', '
    sender='xxx@xyz.com'
    send_open_mail_to='xxx@xyz.com'
    # Create the container (outer) email message.
    msg = MIMEMultipart()
    msg.set_charset("utf-8")
    msg['Subject'] = 'Test'
    msg['From'] = sender
    msg['To'] = COMMASPACE.join(send_open_mail_to)

    text="""
    &lt;html&gt;
    &lt;head&gt;
       &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
       &lt;title&gt;html title&lt;/title&gt;
       &lt;style type="text/css" media="screen"&gt;
           table{
                 background-color: #AAD373;
                 empty-cells:hide;
           }
           td.cell{
                 background-color: white;
           }
       &lt;/style&gt;
     &lt;/head&gt;
     &lt;body&gt;"""

    text+="""&lt;p&gt;&lt;BR&gt;Hi, &lt;BR&gt;Please find below table for Cloned JIRA's:&lt;BR&gt;&lt;/p&gt;
         &lt;table style="border: blue 1px solid;"&gt;

             &lt;tr&gt;&lt;td class="cell"&gt;JIRA Link&lt;/td&gt;&lt;td class="cell"&gt;PRISM URL&lt;/td&gt;&lt;td class="cell"&gt;CR Title&lt;/td&gt;&lt;/tr&gt;"""
for key,value in jira_cr_cloned_dict.items():
             CR_title=value[1].decode('utf-8')
             text+="""&lt;tr&gt;&lt;td class="cell"&gt;%s&lt;/td&gt;&lt;td class="cell"&gt;%s&lt;/td&gt;&lt;td class="cell"&gt;%s&lt;/td&gt;&lt;/tr&gt;""" %(key,value[0],CR_title)
text+=”””&lt;/table&gt;&lt;/body&gt;
     &lt;/html&gt;”””
    HTML_BODY = MIMEText(text, 'html','utf-8')
    Encoders.encode_7or8bit(HTML_BODY)
    msg.attach(HTML_BODY)
    # Send the email via our own SMTP server.
    s = smtplib.SMTP('localhost')
    s.sendmail(sender, send_open_mail_to, msg.as_string())
    s.quit()
</code></pre>

<p>Code segment where jira_cr_cloned_dict is populated :-</p>

<pre><code>CR_title=CR_detail['Title'].encode('utf-8')
print ('CR title in PRISM: %s\n'%CR_title)
CR_list=[prism_url[1:-1],CR_title]
jira_cr_cloned_dict[jira_link]=CR_list
</code></pre>

<p>Upon running the function send_mail_cloned(), I am getting errors such as </p>

<pre><code>File "/usr/lib/python2.6/email/mime/text.py", line 30, in __init__
    self.set_payload(_text, _charset)
  File "/usr/lib/python2.6/email/message.py", line 224, in set_payload
    self.set_charset(charset)
  File "/usr/lib/python2.6/email/message.py", line 266, in set_charset
    self._payload = charset.body_encode(self._payload)
  File "/usr/lib/python2.6/email/charset.py", line 387, in body_encode
    return email.base64mime.body_encode(s)
  File "/usr/lib/python2.6/email/base64mime.py", line 147, in encode
    enc = b2a_base64(s[i:i + max_unencoded])

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 54: ordinal not in range(128)
</code></pre>

<p>I tried not to encode/decode the strings. However, in that case the print %s fails itself.</p>

<p>Could someone please help me figure out the error here while sending email?</p>
