Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unnecessary exclamation marks(!)'s in HTML code

I am emailing the content of a text file "gerrit.txt" @ http://pastie.org/8289257 in outlook using the below code, however after the email is sent when I look at the source code( @http://pastie.org/8289379) of the email in outlook ,i see unnecessary exclamation markds(!)'s in the code which is messing up the output, can anyone provide inputs on why is it so and how to avoid this ?

from email.mime.text import MIMEText
from smtplib import SMTP

def email (body,subject):
    msg = MIMEText("%s" % body, 'html')
    msg['Content-Type'] = "text/html; charset=UTF8"
    msg['Subject'] = subject
    s = SMTP('localhost',25)
    s.sendmail('[email protected]', ['[email protected]'],msg=msg.as_string())

def main ():
    # open gerrit.txt and read the content into body
    with open('gerrit.txt', 'r') as f:
        body = f.read()
    subject = "test email"
    email(body,subject)
    print "Done"

if __name__ == '__main__':
    main()
like image 732
user2341103 Avatar asked Sep 01 '13 23:09

user2341103


1 Answers

Some info available here: http://bugs.python.org/issue6327

Note that mailservers have a 990-character limit on each line contained within an email message. If an email message is sent that contains lines longer than 990-characters, those lines will be subdivided by additional line ending characters, which can cause corruption in the email message, particularly for HTML content. To prevent this from occurring, add your own line-ending characters at appropriate locations within the email message to ensure that no lines are longer than 990 characters.

I think you must split your html to some lines. You can use textwrap.wrap method.

like image 181
Murat Çorlu Avatar answered Sep 17 '22 13:09

Murat Çorlu