Traceback (most recent call last):
  File "C:/Users/James/Desktop/Quikemail.py", line 54, in send
    s.sendmail(me, you, msg.as_string())
  File "C:\python 25\lib\email\message.py", line 131, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "C:\python 25\lib\email\generator.py", line 84, in flatten
    self._write(msg)
  File "C:\python 25\lib\email\generator.py", line 116, in _write
    self._write_headers(msg)
  File "C:\python 25\lib\email\generator.py", line 162, in _write_headers
    header_name=h, continuation_ws='\t').encode()
  File "C:\python 25\lib\email\header.py", line 402, in encode
    return self._encode_chunks(newchunks, maxlinelen)
  File "C:\python 25\lib\email\header.py", line 362, in _encode_chunks
    _max_append(chunks, s, maxlinelen, extra)
  File "C:\python 25\lib\email\quoprimime.py", line 97, in _max_append
    L.append(s.lstrip())
AttributeError: 'list' object has no attribute 'lstrip'

My code is here:

#!/usr/bin/env python

import smtplib,traceback

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = raw_input("Email:")
password = raw_input("Password:")
def send(you,text,subject):
    global me,password
    # Create message container - the correct MIME type is multipart/alternative.
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = me
    msg['To'] = you

    # Create the body of the message (a plain-text and an HTML version).
    html = text.replace("\n","<br>")
    text = text.replace("<a href=","").replace(">","").replace("</a>","")
    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(text, 'plain')
    part2 = MIMEText(html, 'html')

    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)
    print 'smtp.'+me.split("@", 1)[1]+":587"
    s = smtplib.SMTP('smtp.'+me.split("@", 1)[1]+":587")
    # sendmail function takes 3 arguments: sender's address, recipient's address
    # and message to send - here it is sent as one string.
    try:
        s.ehlo()
        s.helo()
        s.login(me, password)
    except smtplib.SMTPAuthenticationError:
        print"Bad password."
        me = raw_input("Email:")
        password = raw_input("Password:")
        send(you,text,subject)
    except smtplib.SMTPException:
        print"Unable to authenticate, probaly not supported"
        #print traceback.format_exc(limit=0).lstrip("Traceback (most recent call last):\n")
    except:
        print "Unknown Error:"
        print traceback.format_exc(limit=0).lstrip("Traceback (most recent call last):\n")
    try:
        s.ehlo()
        s.helo()
        s.starttls()
        s.ehlo()
        s.helo()
        s.sendmail(me, you, msg.as_string())
    except smtplib.SMTPRecipientsRefused:
        print "Email refused to be sent to all addresses."
    except smtplib.SMTPSenderRefused:
        print "Refused to send from current address"
        me = raw_input("Email:")
        password = raw_input("Password:")
        send(you,text,subject)
    except smtplib.SMTPDataError:
        print "Unexpected Error Code,Resending..."
        send(you,text,subject)
    except RuntimeError:
        print "This program does not support it."
    except smtplib.SMTPException:
        s.ehlo()
        s.helo()
        s.sendmail(me, you, msg.as_string())
    except:
        print "Unknown Error:"
        print traceback.format_exc()#.lstrip("Traceback (most recent call last):\n") #temporarily turn off error showing for debugging
    s.quit()
while True:
    sendto = raw_input("To(s) (seperated by a comma):").split(",")
    subject = raw_input("Subject:")
    text = ""
    t = ""
    while t != "end":
        text = text + t+"\n"
        t = raw_input("Body>")
    send(sendto,text,subject)

Recommended Answers

The problem seems to be in one of your library files. Can't help you since Python25 has died many years ago.

Jump to Post

Somehow you are sending through a list object rather then a string.

Jump to Post

All 5 Replies

The problem seems to be in one of your library files. Can't help you since Python25 has died many years ago.

Somehow you are sending through a list object rather then a string.

impossible.I usedmsg.as_string()

The error is in the call to msg.as_string()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.