473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Sending mail with attachment...

Hi,

I have now eventually finished my newbie-backup script and I'm very
proud of the way it functions...

Anyways, I am looking for an easy way to use smtplib to send an email
with the output log of the script to multiple accounts. I need to use
it with a smtp server, and cannot pipe it directly to sendmail.

I have tried about 50 different ways that I have googled for in the
last 6 hours, but none of them work, I keep on getting errors.

The script runs on a Linux system.

Thanks for any help.

May 13 '06 #1
5 1916
Hi Guys,

I just wanted to post the error, and then also the coda that causes
it....I get this no matter what I do to this, and I don't understand
it. Any help would be welcome. Thank you

Error
::
Traceback (most recent call last):
File "/home/merrigan/projects/Backup Script/hobbitarchive.py", line
113, in ?
mailSender()
File "/home/merrigan/projects/Backup Script/hobbitarchive.py", line
74, in mailSender
s.sendmail(fromaddy, recievelist, mesg.as_string())
File "/usr/lib/python2.4/email/Message.py", line 129, in as_string
g.flatten(self, unixfrom=unixfrom)
File "/usr/lib/python2.4/email/Generator.py", line 82, in flatten
self._write(msg)
File "/usr/lib/python2.4/email/Generator.py", line 120, in _write
self._write_headers(msg)
File "/usr/lib/python2.4/email/Generator.py", line 166, in
_write_headers
header_name=h, continuation_ws='\t').encode()
File "/usr/lib/python2.4/email/Header.py", line 395, in encode
return self._encode_chunks(newchunks, maxlinelen)
File "/usr/lib/python2.4/email/Header.py", line 355, in
_encode_chunks
_max_append(chunks, s, maxlinelen, extra)
File "/usr/lib/python2.4/email/quopriMIME.py", line 79, in
_max_append
L.append(s.lstrip())
AttributeError: 'list' object has no attribute 'lstrip'

::

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()

::

Thanks a lot :)

May 13 '06 #2
On 13 May 2006 03:13:33 -0700, Merrigan <ch***********@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 :)
May 13 '06 #3
Replace:
mesg['To'] = recievelist
By:
mesg['To'] = ', '.join(recievelist)

May 13 '06 #4
Merrigan wrote:
mesg['To'] = recievelist


It's already been pointed out that this is a problem, but I just wanted
to mention also that 'recieve' is misspelled, in case that affects
anything, or others who might read/use the code.
May 13 '06 #5
Merrigan escribió:
Hi,

I have now eventually finished my newbie-backup script and I'm very
proud of the way it functions...

Anyways, I am looking for an easy way to use smtplib to send an email
with the output log of the script to multiple accounts. I need to use
it with a smtp server, and cannot pipe it directly to sendmail.

I have tried about 50 different ways that I have googled for in the
last 6 hours, but none of them work, I keep on getting errors.

The script runs on a Linux system.

Thanks for any help.


I have a python script in production doing what you want using smtplib
and it works perfectly. Send us your code and the errors you are getting.
Regards.

--
Marcelo Ramos
Fedora Core 5 | 2.6.16
Socio UYLUG Nro 125

May 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dragos Marian Barbu | last post by:
Recently I tried to develop a function to help me sending e-mail messages with more than one attachment. Everything is working OK when I am sebding messages with one attachment, but when I try to...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
3
by: dnuos | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Here's some details: ...
6
by: Rushwire | last post by:
Does anybody know how to send a meeting request using an ics/vcs (VCalendar) attachment from an asp.net page. I don't want my users to have to double click on the attachment but rather that it is...
2
by: prasenjit2007 | last post by:
Hello, can u help me sending Email with attachments using the Class phpMailer. On the website I have a link to an html form in which I input the parameters with the names 1)from(textbox name)...
7
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any...
3
by: raj200809 | last post by:
when i m sending mail i received error from symantec Antivirus" Your email message was unable to be sent because your mail server rejected the message 550-5.7.1 the ip you’re using to send mail is...
3
by: virtualweb | last post by:
Hello: I need to send a bit of HTML and Javascrpt on the body of an email from my perl script in order to have the recipient get a link that will openup a new window with a PopUp. For some...
1
maliksleo
by: maliksleo | last post by:
hi i am using the following class for email sending but getting this error "Failure sending mail" Imports System.Net.Mail Public Class MailHelper ''' <summary> ''' Sends an mail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.