Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Python Will Not Send Email!!

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


victorsubervi at gmail

Nov 19, 2009, 7:28 AM

Post #1 of 12 (995 views)
Permalink
Python Will Not Send Email!!

Hi;
I created this testMail.py file as root:

#!/usr/bin/env python
import smtplib
session = smtplib.SMTP("localhost")
subject = "Hello, "
header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n"
message = "world!"
email_from = "victor [at] is"
email_to = ["email [at] myhost"]
session.sendmail(email_from, email_to, header+messages)

[root [at] 13gem globalsolutionsgroup.vi]# chmod 755 testMail.py
[root [at] 13gem globalsolutionsgroup.vi]# python testMail.py
Traceback (most recent call last):
File "testMail.py", line 2, in ?
import smtplib
File "/usr/lib64/python2.4/smtplib.py", line 49, in ?
from email.base64MIME import encode as encode_base64
ImportError: No module named base64MIME

What gives??
TIA,
Victor


victorsubervi at gmail

Nov 19, 2009, 7:29 AM

Post #2 of 12 (981 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Thu, Nov 19, 2009 at 11:28 AM, Victor Subervi <victorsubervi [at] gmail>wrote:

> Hi;
> I created this testMail.py file as root:
>
> #!/usr/bin/env python
> import smtplib
> session = smtplib.SMTP("localhost")
> subject = "Hello, "
> header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n"
> message = "world!"
> email_from = "victor [at] is"
> email_to = ["email [at] myhost"]
> session.sendmail(email_from, email_to, header+messages)
>
> [root [at] 13gem globalsolutionsgroup.vi]# chmod 755 testMail.py
> [root [at] 13gem globalsolutionsgroup.vi]# python testMail.py
> Traceback (most recent call last):
> File "testMail.py", line 2, in ?
> import smtplib
> File "/usr/lib64/python2.4/smtplib.py", line 49, in ?
> from email.base64MIME import encode as encode_base64
> ImportError: No module named base64MIME
>
> What gives??
> TIA,
> Victor
>
PS Python 2.4 on CentOS


carsten.haese at gmail

Nov 19, 2009, 9:32 AM

Post #3 of 12 (974 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

Victor Subervi wrote:
> Hi;
> I created this testMail.py file as root:
>
> #!/usr/bin/env python
> import smtplib
> session = smtplib.SMTP("localhost")
> subject = "Hello, "
> header = "Subject: %s \r\nContent-type: text/html; charset=utf-8\r\n\r\n"
> message = "world!"
> email_from = "victor [at] is"
> email_to = ["email [at] myhost <mailto:email [at] myhost>"]
> session.sendmail(email_from, email_to, header+messages)
>
> [root [at] 13gem globalsolutionsgroup.vi <http://globalsolutionsgroup.vi>]#
> chmod 755 testMail.py
> [root [at] 13gem globalsolutionsgroup.vi <http://globalsolutionsgroup.vi>]#
> python testMail.py
> Traceback (most recent call last):
> File "testMail.py", line 2, in ?
> import smtplib
> File "/usr/lib64/python2.4/smtplib.py", line 49, in ?
> from email.base64MIME import encode as encode_base64
> ImportError: No module named base64MIME
>
> What gives??

Do you have a file called "email.py" in your current directory or
anywhere else on Python's path outside of the standard library? If so,
it's hiding the real email module from your script and you'll need to
get rid of "your" email.py by renaming or moving it.

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


kevin.p.dwyer at gmail

Nov 19, 2009, 2:01 PM

Post #4 of 12 (976 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote:

Hello Victor,

There are some pages on the internet that suggest that this problem my be
caused by a module named email.py (or email.pyc) in your pythonpath. If
you try import smtplib in the interpreter do you get this error message?
If so, start a new interpreter session and try import email - is the
email module imported from the stdlib?

If these steps don't help, it might be useful if you can tell us which
Linux distribution you are using.

Cheers,

Kev

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 20, 2009, 4:58 AM

Post #5 of 12 (966 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer <kevin.p.dwyer [at] gmail> wrote:

> On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote:
>
> Hello Victor,
>
> There are some pages on the internet that suggest that this problem my be
> caused by a module named email.py (or email.pyc) in your pythonpath. If
> you try import smtplib in the interpreter do you get this error message?
> If so, start a new interpreter session and try import email - is the
> email module imported from the stdlib?
>

Both of these import just fine.

>
> If these steps don't help, it might be useful if you can tell us which
> Linux distribution you are using.
>

Python 2.4.3
[root [at] 13gem ~]# uname -a
Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25
MSK 2009 x86_64 x86_64 x86_64 GNU/Linux
CentOS 5.4 final
TIA,
V


kevin.p.dwyer at gmail

Nov 20, 2009, 7:05 AM

Post #6 of 12 (981 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Fri, 20 Nov 2009 07:58:55 -0500, Victor Subervi wrote:

> On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer <kevin.p.dwyer [at] gmail>
> wrote:
>
>> On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote:
>>
>> Hello Victor,
>>
>> There are some pages on the internet that suggest that this problem my
>> be caused by a module named email.py (or email.pyc) in your pythonpath.
>> If you try import smtplib in the interpreter do you get this error
>> message? If so, start a new interpreter session and try import email -
>> is the email module imported from the stdlib?
>>
>>
> Both of these import just fine.
>
>
>> If these steps don't help, it might be useful if you can tell us which
>> Linux distribution you are using.
>>
>>
> Python 2.4.3
> [root [at] 13gem ~]# uname -a
> Linux 13gems.com.13gems.com 2.6.18-028stab064.8 #1 SMP Fri Nov 6
> 11:28:25 MSK 2009 x86_64 x86_64 x86_64 GNU/Linux CentOS 5.4 final
> TIA,
> V
> <div class="gmail_quote">On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer
> <span dir="ltr">&lt;<a
> href="mailto:kevin.p.dwyer [at] gmail">kevin.p.dwyer [at] gmail</a>&gt;</
> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0
> .8ex;border-left:1px #ccc solid;padding-left:1ex;"> On Thu, 19 Nov 2009
> 11:28:37 -0400, Victor Subervi wrote:<br> <br>
> Hello Victor,<br>
> <br>
> There are some pages on the internet that suggest that this problem my
> be<br> caused by a module named email.py (or email.pyc) in your
> pythonpath.  If<br> you try import smtplib in the interpreter do you get
> this error message?<br> If so, start a new interpreter session and try
> import email - is the<br> email module imported from the
> stdlib?<br></blockquote><div><br></div><div>Both of these import just
> fine. </div><blockquote class="gmail_quote" style="margin:0 0 0
> .8ex;border-left:1px #ccc solid;padding-left:1ex;"> <br>
> If these steps don&#39;t help, it might be useful if you can tell us
> which<br> Linux distribution you are
> using.<br></blockquote><div><br></div><div>Python
> 2.4.3</div><div><div>[root [at] 13gem ~]# uname -a</div><div>Linux <a
> href="http://13gems.com.13gems.com">13gems.com.13gems.com</a>
> 2.6.18-028stab064.8 #1 SMP Fri Nov 6 11:28:25 MSK 2009 x86_64 x86_64
> x86_64 GNU/Linux</div> <div>CentOS 5.4
> final</div><div>TIA,</div><div>V</div></div></div>

Hello Victor,

I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as
yours but also running python 2.4.3). It ran without error. So I
suspect that either you have a rogue email module/package on your machine
or there's something wrong with the python install.

You could try:

import email
email.__version__

My interpreter responds "3.0.1" If you get a different response that
suggests a dodgy module somewhere - try email.__file__ and see where it's
located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc).

If the version number is "3.0.1" on your machine then I would check the
contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module
is missing.

Cheers,

Kev

--
http://mail.python.org/mailman/listinfo/python-list


carsten.haese at gmail

Nov 20, 2009, 7:14 AM

Post #7 of 12 (967 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

Victor Subervi wrote:
> On Thu, Nov 19, 2009 at 5:01 PM, Kev Dwyer <kevin.p.dwyer [at] gmail
> <mailto:kevin.p.dwyer [at] gmail>> wrote:
>
> On Thu, 19 Nov 2009 11:28:37 -0400, Victor Subervi wrote:
>
> Hello Victor,
>
> There are some pages on the internet that suggest that this problem
> my be
> caused by a module named email.py (or email.pyc) in your pythonpath. If
> you try import smtplib in the interpreter do you get this error message?
> If so, start a new interpreter session and try import email - is the
> email module imported from the stdlib?
>
>
> Both of these import just fine.

Kevin neglected to mention that the new interpreter session must be
started in the same directory as the one you're in when you run your
testMail.py script. Since he didn't mention that, we can't be sure that
that's what you did, so this experiment doesn't prove anything.

Please show us a copy-and-paste of your command line window contents
that result from executing <<python testMail.py>> and then executing
<<python -c "import email; print email">> immediately thereafter.

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 20, 2009, 7:49 AM

Post #8 of 12 (962 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Fri, Nov 20, 2009 at 11:05 AM, Kev Dwyer <kevin.p.dwyer [at] gmail> wrote:

> I ran your script on a CentOS vm (5.2 server 32bit, not quite the same as
> yours but also running python 2.4.3). It ran without error. So I
> suspect that either you have a rogue email module/package on your machine
> or there's something wrong with the python install.
>
> You could try:
>
> import email
> email.__version__
>
> My interpreter responds "3.0.1" If you get a different response that
> suggests a dodgy module somewhere - try email.__file__ and see where it's
> located (my interpreter returns /usr/lib/python2.4/email/__init__.pyc).
>
> If the version number is "3.0.1" on your machine then I would check the
> contents of /usr/lib64/python2.4/email/. Perhaps the base64MIME module
> is missing.
>

>>> import email
>>> email.__version__
'3.0.1'
>>>
[root [at] 13gem cart]# ls /usr/lib64/python2.4/email/
base64MIME.py Encoders.pyo Generator.pyc Iterators.py
MIMEAudio.pyo MIMEMessage.pyc MIMEText.py Parser.pyo
base64MIME.pyc Errors.py Generator.pyo Iterators.pyc
MIMEBase.py MIMEMessage.pyo MIMEText.pyc quopriMIME.py
base64MIME.pyo Errors.pyc Header.py Iterators.pyo
MIMEBase.pyc MIMEMultipart.py MIMEText.pyo quopriMIME.pyc
Charset.py Errors.pyo Header.pyc Message.py
MIMEBase.pyo MIMEMultipart.pyc _parseaddr.py quopriMIME.pyo
Charset.pyc FeedParser.py Header.pyo Message.pyc
MIMEImage.py MIMEMultipart.pyo _parseaddr.pyc test
Charset.pyo FeedParser.pyc __init__.py Message.pyo
MIMEImage.pyc MIMENonMultipart.py _parseaddr.pyo Utils.py
Encoders.py FeedParser.pyo __init__.pyc MIMEAudio.py
MIMEImage.pyo MIMENonMultipart.pyc Parser.py Utils.pyc
Encoders.pyc Generator.py __init__.pyo MIMEAudio.pyc
MIMEMessage.py MIMENonMultipart.pyo Parser.pyc Utils.pyo

Any other ideas?
TIA,
V


victorsubervi at gmail

Nov 20, 2009, 7:58 AM

Post #9 of 12 (962 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese <carsten.haese [at] gmail>wrote:

> Kevin neglected to mention that the new interpreter session must be
> started in the same directory as the one you're in when you run your
> testMail.py script. Since he didn't mention that, we can't be sure that
> that's what you did, so this experiment doesn't prove anything.
>
> Please show us a copy-and-paste of your command line window contents
> that result from executing <<python testMail.py>> and then executing
> <<python -c "import email; print email">> immediately thereafter.
>

[root [at] 13gem globalsolutionsgroup.vi]# python testMail.py
Traceback (most recent call last):
File "testMail.py", line 2, in ?
import smtplib
File "/usr/lib64/python2.4/smtplib.py", line 49, in ?
from email.base64MIME import encode as encode_base64
ImportError: No module named base64MIME
[root [at] 13gem globalsolutionsgroup.vi]# python -c "import email; print email"
<module 'email' from 'email.pyc'>
TIA,
V


carsten.haese at gmail

Nov 20, 2009, 8:38 AM

Post #10 of 12 (968 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

Victor Subervi wrote:
> On Fri, Nov 20, 2009 at 11:14 AM, Carsten Haese <carsten.haese [at] gmail
> <mailto:carsten.haese [at] gmail>> wrote:
> Please show us a copy-and-paste of your command line window contents
> that result from executing <<python testMail.py>> and then executing
> <<python -c "import email; print email">> immediately thereafter.
>
>
> [root [at] 13gem globalsolutionsgroup.vi <http://globalsolutionsgroup.vi>]#
> python testMail.py
> Traceback (most recent call last):
> File "testMail.py", line 2, in ?
> import smtplib
> File "/usr/lib64/python2.4/smtplib.py", line 49, in ?
> from email.base64MIME import encode as encode_base64
> ImportError: No module named base64MIME
> [root [at] 13gem globalsolutionsgroup.vi <http://globalsolutionsgroup.vi>]#
> python -c "import email; print email"
> <module 'email' from 'email.pyc'>

Thank you. This proves conclusively that there IS in fact a file called
email.pyc (and/or email.py) in your directory next to testMail.py. It is
this email.pyc that is being imported instead of the email.py from the
Python library. Getting rid of both email.py and email.pyc (by renaming
them, deleting them, or moving them somewhere else) will fix your problem.

--
Carsten Haese
http://informixdb.sourceforge.net

--
http://mail.python.org/mailman/listinfo/python-list


kevin.p.dwyer at gmail

Nov 20, 2009, 8:56 AM

Post #11 of 12 (966 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Fri, 20 Nov 2009 11:58:00 -0400, Victor Subervi wrote:

Hello Victor,

Carsten's well-specified instruction has identified your problem.

>[root [at] 13gem globalsolutionsgroup.vi]# python -c "import email; print
>email"
><module 'email' from 'email.pyc'>

There is a file named email.pyc, most likely in your current directory,
that is masking the email package in the standard library. Remove/rename
email.pyc and email.py, if it exists.

Cheers,

Kevin

--
http://mail.python.org/mailman/listinfo/python-list


victorsubervi at gmail

Nov 20, 2009, 9:39 AM

Post #12 of 12 (969 views)
Permalink
Re: Python Will Not Send Email!! [In reply to]

On Fri, Nov 20, 2009 at 12:38 PM, Carsten Haese <carsten.haese [at] gmail>wrote:

> Thank you. This proves conclusively that there IS in fact a file called
> email.pyc (and/or email.py) in your directory next to testMail.py. It is
> this email.pyc that is being imported instead of the email.py from the
> Python library. Getting rid of both email.py and email.pyc (by renaming
> them, deleting them, or moving them somewhere else) will fix your problem.
>

Thank you! It did indeed fix that problem. Now I get this traceback:

/var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py 52
session.sendmail(clientEmail, ourEmail1, header+msg)
53 # session.sendmail(clientEmail, ourEmail2, header+msg)
54
55 mailSpreadsheet()
56
*mailSpreadsheet* = <function mailSpreadsheet>
/var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet
*() 47 order += 'TOTAL: $' + str(total)
48
msg = 'Here is the order from %s:\n\n %s' % (string.replace(client,
'_', ' '), order)
49 session = smtplib.SMTP("localhost")
50 session.login(user, passwd) # only if it requires auth
51
header = "Subject: %s \r\nContent-type: text/html;
charset=utf-8\r\n\r\n" % subject
session *undefined*, *global* *smtplib* = <module 'smtplib' from
'/usr/lib64/python2.4/smtplib.pyc'>, smtplib.*SMTP* = <class smtplib.SMTP>
/usr/lib64/python2.4/smtplib.py in *__init__*(self=<smtplib.SMTP instance>,
host='localhost', port=0, local_hostname=None) 242
self.esmtp_features = {}
243 if host:
244 (code, msg) = self.connect(host, port)
245 if code != 220:
246 raise SMTPConnectError(code, msg)
code *undefined*, msg *undefined*, *self* = <smtplib.SMTP instance>, self.*
connect* = <bound method SMTP.connect of <smtplib.SMTP instance>>, *host* =
'localhost', *port* = 0 /usr/lib64/python2.4/smtplib.py in
*connect*(self=<smtplib.SMTP
instance>, host='localhost', port=25) 305 if not self.sock:
306 raise socket.error, msg
307 (code, msg) = self.getreply()
308 if self.debuglevel > 0: print>>stderr, "connect:", msg
309 return (code, msg)
code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* =
<smtplib.SMTP instance>, self.*getreply* = <bound method SMTP.getreply of
<smtplib.SMTP instance>> /usr/lib64/python2.4/smtplib.py in
*getreply*(self=<smtplib.SMTP
instance>) 349 if line == '':
350 self.close()
351
raise SMTPServerDisconnected("Connection unexpectedly closed")
352
if self.debuglevel > 0: print>>stderr, 'reply:', repr(line)
353 resp.append(line[4:].strip())
*global* *SMTPServerDisconnected* = <class smtplib.SMTPServerDisconnected>*
SMTPServerDisconnected*: Connection unexpectedly closed
args = ('Connection unexpectedly closed',)

Why did this connection close? How do I fix it?
TIA,
V

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.