Sending mail with attachment...

Tim Williams tdw at tdw.net
Sat May 13 09:18:17 EDT 2006


On 13 May 2006 03:13:33 -0700, Merrigan <charl.loubser at gmail.com> wrote:

> ::
>
> Code
> ::
> def mailSender():
>         openlogmsg = open(completelog, 'rb')
>         mesg = MIMEText(openlogmsg.read())
>         openlogmsg.close()
>         mesg['Subject'] = subject
>         mesg['From'] = fromaddy
>         mesg['To'] = recievelist
>         s = smtplib.SMTP(smtpserver)
> #       s.connect(smtpserver)
>         s.sendmail(fromaddy, recievelist, mesg.as_string())
>         s.quit()

You are passing a list to the "To:" header,  it should be a string.

The "To" header needs to be a text representation of some/all/None of
the recipients, or it can contain unrelated text,  its a field that
the mail client uses to display the email details, it is not related
to the sending of the email.

The recievelist used during the sendmail function should contain the
list of recipient address(es), which means all the TO , CC and BCC
addresses for that email - or it can be  a string of 1 address if you
are on a recent version of Python and there is only 1 recipient.

HTH :)



More information about the Python-list mailing list