Re: Getting "LazyImporter' object is not callable" error when trying to send email using python smtplib

2018-03-26 Thread Sum
Thanks Steve for your inputs.
Now I am able to run the code successfully.

# Made changes to import statements as below:
from email.mime.base import MIMEBase
from email.mime.text import MIMEText


Apologies for the typo and indentation error in above mail.

Regards,
Sumit


On Mon, Mar 26, 2018 at 6:04 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Mon, 26 Mar 2018 16:47:26 +0530, Sum wrote:
>
> > Hi,
> >
> > Getting "LazyImporter' object is not callable" error. I have enabled
> > allow less secure app setting in sender gmail.
> >
> > Code :
>
> The code you show is not the same as the code you are actually running.
> The error message you give says:
>
> File "test_mail.py", line 64, in
>   send_email(to, SUBJECT, TEXT, attachment_file)
> File "test_mail.py", line 24, in send_email
>   msg.attach(MIMEText(text))
> TypeError: 'LazyImporter' object is not callable
>
>
> Notice the quoted line 24. Here it is again:
>
> msg.attach(MIMEText(text))
>
> But line 24 in the code you give us is:
>
> msg.attach(part)
>
>
> which is different. Also, you have a line of code:
>
> except smtplib.SMTPException,error::
>
> Notice the two colons at the end of the line? That's a syntax error. So
> the code you have shown us cannot possibly be the same as the code you
> are running.
>
> Please review your code, copy and paste the complete traceback, starting
> with the line "Traceback", and make sure that you have run the code you
> show us.
>
> It might help to read this page:
>
> http://sscce.org/
>
> It's written for Java programmers, but the ideas apply equally to Python.
>
>
> Thank you,
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting "LazyImporter' object is not callable" error when trying to send email using python smtplib

2018-03-26 Thread Steven D'Aprano
On Mon, 26 Mar 2018 16:47:26 +0530, Sum wrote:

> Hi,
> 
> Getting "LazyImporter' object is not callable" error. I have enabled
> allow less secure app setting in sender gmail.
> 
> Code :

The code you show is not the same as the code you are actually running. 
The error message you give says:

File "test_mail.py", line 64, in 
  send_email(to, SUBJECT, TEXT, attachment_file) 
File "test_mail.py", line 24, in send_email
  msg.attach(MIMEText(text))
TypeError: 'LazyImporter' object is not callable


Notice the quoted line 24. Here it is again:

msg.attach(MIMEText(text))

But line 24 in the code you give us is:

msg.attach(part)


which is different. Also, you have a line of code:

except smtplib.SMTPException,error::

Notice the two colons at the end of the line? That's a syntax error. So 
the code you have shown us cannot possibly be the same as the code you 
are running.

Please review your code, copy and paste the complete traceback, starting 
with the line "Traceback", and make sure that you have run the code you 
show us.

It might help to read this page:

http://sscce.org/

It's written for Java programmers, but the ideas apply equally to Python.


Thank you,



-- 
Steve

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


Getting "LazyImporter' object is not callable" error when trying to send email using python smtplib

2018-03-26 Thread Sum
Hi,

Getting "LazyImporter' object is not callable" error.
I have enabled allow less secure app setting in sender gmail.

Code :

import smtplib
from email import MIMEBase
from email import MIMEText
from email.mime.multipart import MIMEMultipart
from email import Encoders
import os

def send_email(to, subject, text, filenames):
try:
gmail_user = 'x...@gmail.com'
gmail_pwd = ''

msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = ", ".join(to)
msg['Subject'] = subject
msg.attach(MIMEText(text))

for file in filenames:
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(file, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment;
filename="%s"'% os.path.basename(file))
msg.attach(part)

mailServer = smtplib.SMTP("smtp.gmail.com:465")
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmail_user, gmail_pwd)
mailServer.sendmail(gmail_user, to, msg.as_string())
mailServer.close()
print('successfully sent the mail')

except smtplib.SMTPException,error::
print str(error)

if __name__ == '__main__':
attachment_file = ['t1.txt','t2.csv']
to = "xxx...@gmail.com"
TEXT = "Hello everyone"
SUBJECT = "Testing sending using gmail"

send_email(to, SUBJECT, TEXT, attachment_file)


Getting below error :
File "test_mail.py", line 64, in send_email(to, SUBJECT, TEXT,
attachment_file) File "test_mail.py", line 24, in send_email
msg.attach(MIMEText(text)) TypeError: 'LazyImporter' object is not callable
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: smtplib TimeoutError not catch

2016-10-12 Thread Joaquin Alzola
>Not surprisingly, the exception you should catch is simply TimeoutError:

 >try:
 >server.sendmail(sender, receivers, msg.as_string())
 >except TimeoutError as e:
 >print("SMTP could not be contacted: %s" % e)
 >finally:
 >   server.quit()

The error was thrown by another line :S, after putting the TimeoutError it work 
OK (with the proper exception line).

I had to apply a WA server = None to avoid the finally " UnboundLocalError: 
local variable 'server' referenced before assignment "

server = None
   try:
server = smtplib.SMTP('smtp.mail.com')   <--- this is where the 
exception was happening.
server.set_debuglevel(True) # show communication with the server
server.sendmail(sender, receivers, msg.as_string())
except TimeoutError as e:
print("SMTP could not be access: %s"%e)
pass
finally:
if server:
server.quit()


Joaquin


This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib TimeoutError not catch

2016-10-12 Thread MRAB

On 2016-10-12 14:21, Joaquin Alzola wrote:

Hi Guys

Try to connect to the smtp via smtplib.

The connection is down because the Firewall has not been open yet so the 
exception is something that should appear.
Now I want to catch this timeout in case error happens in future.

Here the exception trace.

[2016-10-12 14:14:06,289] ERROR in app: Exception on /api/barredMSISDN [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1988, in 
wsgi_app
response = self.full_dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1641, in 
full_dispatch_request
rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1544, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in 
reraise
raise value
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1639, in 
full_dispatch_request
rv = self.dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1625, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/main.py", line 34, in barredMSISDN
smtp_con(http_json)
  File "/root/main.py", line 134, in smtp_con
server = smtplib.SMTP('smtp.lebara.com')
  File "/usr/local/lib/python3.4/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.4/smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.4/smtplib.py", line 292, in _get_socket
self.source_address)
  File "/usr/local/lib/python3.4/socket.py", line 516, in create_connection
raise err
  File "/usr/local/lib/python3.4/socket.py", line 507, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out


How to catch such exception? ... have been trying with a lot of combinations 
(of course except the correct one :))

try:
server.sendmail(sender, receivers, msg.as_string())
except Exception as e: <-- have try with many combinations here
print("SMTP could not be contacted: %s",e)
pass
finally:
   server.quit()


Not surprisingly, the exception you should catch is simply TimeoutError:

try:
server.sendmail(sender, receivers, msg.as_string())
except TimeoutError as e:
print("SMTP could not be contacted: %s" % e)
finally:
server.quit()

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


smtplib TimeoutError not catch

2016-10-12 Thread Joaquin Alzola
Hi Guys

Try to connect to the smtp via smtplib.

The connection is down because the Firewall has not been open yet so the 
exception is something that should appear.
Now I want to catch this timeout in case error happens in future.

Here the exception trace.

[2016-10-12 14:14:06,289] ERROR in app: Exception on /api/barredMSISDN [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1988, in 
wsgi_app
response = self.full_dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1641, in 
full_dispatch_request
rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1544, in 
handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.4/site-packages/flask/_compat.py", line 33, in 
reraise
raise value
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1639, in 
full_dispatch_request
rv = self.dispatch_request()
  File "/usr/local/lib/python3.4/site-packages/flask/app.py", line 1625, in 
dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/main.py", line 34, in barredMSISDN
smtp_con(http_json)
  File "/root/main.py", line 134, in smtp_con
server = smtplib.SMTP('smtp.lebara.com')
  File "/usr/local/lib/python3.4/smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.4/smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.4/smtplib.py", line 292, in _get_socket
self.source_address)
  File "/usr/local/lib/python3.4/socket.py", line 516, in create_connection
raise err
  File "/usr/local/lib/python3.4/socket.py", line 507, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out


How to catch such exception? ... have been trying with a lot of combinations 
(of course except the correct one :))

try:
server.sendmail(sender, receivers, msg.as_string())
except Exception as e: <-- have try with many combinations here
print("SMTP could not be contacted: %s",e)
pass
finally:
   server.quit()

Joaquin
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [smtplib] how to assure login was succesful?

2016-05-25 Thread dieter
maurice  writes:
> Once my python script reaches the point where I login in my email account 
> with: server.login(username,password) (where server server = 
> smtplib.SMTP('smtp.office365.com:587')), it returns a tuple like this:
>
> (235,
>  '2.7.0 Authentication successful target host [address here]')

Try a wrong login. I would expect you to get some kind of exception.

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


[smtplib] how to assure login was succesful?

2016-05-24 Thread maurice
Hello to all.

I have the following question:

Once my python script reaches the point where I login in my email account with: 
server.login(username,password) (where server server = 
smtplib.SMTP('smtp.office365.com:587')), it returns a tuple like this:

(235,
 '2.7.0 Authentication successful target host [address here]')

This method returns a tuple (code, resp). Just want to confirm if I use a 
variable to store code alone I should check if it is 235 or not, by looking at 
the reference it seems it is the only code value that does not raise an 
exception.

Thank you.


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


smtplib not working when python run under windows service via Local System account

2016-05-05 Thread loial
I have a python 2.7.10 script which is being run under a windows service on 
windows 2012 server .
The python script uses smtplib to send an email.

It works fine when the windows service is run as a local user, but not when the 
windows service is configured to run as Local System account. I get no 
exception from smtplib, but the email fails to arrive.

Any ideas?

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


Re: smtplib not working as expected

2014-12-27 Thread Juan Christian
Denis it was already resolved, check my message above. ^^
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib not working as expected

2014-12-27 Thread Tim Chase
On 2014-12-27 14:28, Denis McMahon wrote:
> On Sat, 27 Dec 2014 02:52:39 +, Juan Christian wrote:
> > reply: b'550 SMTP is available only with SSL or TLS connection
> > enabled.\r\n'
> > reply: retcode (550); Msg: b'SMTP is available only with SSL or
> > TLS connection enabled.'
> 
> ^^ have a guess what these messages in the traceback mean.

It means that your SMTP server bytes? ;-)

-tkc



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


Re: smtplib not working as expected

2014-12-27 Thread Denis McMahon
On Sat, 27 Dec 2014 02:52:39 +, Juan Christian wrote:

> So, I changed the code how you said, but still not working.
> Traceback:
> 
> reply: b'550 SMTP is available only with SSL or TLS connection
> enabled.\r\n'
> reply: retcode (550); Msg: b'SMTP is available only with SSL or TLS
> connection enabled.'

^^ have a guess what these messages in the traceback mean.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib not working as expected

2014-12-27 Thread Juan Christian
On Sat Dec 27 2014 at 1:23:12 AM Vincent Vande Vyvre <
vincent.vande.vy...@telenet.be> wrote:
Try with the TLS:

Many thanks, working like a charm, code:

server = smtplib.SMTP('smtp.mail.ru')
server.starttls()
server.ehlo()
server.login('SENDER EMAIL GOES HERE', 'PASSWD GOES HERE')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib not working as expected

2014-12-26 Thread Vincent Vande Vyvre

Le 27/12/2014 03:52, Juan Christian a écrit :
On Fri Dec 26 2014 at 11:07:30 PM MRAB <mailto:pyt...@mrabarnett.plus.com>> wrote:

According to the docs, if you let the port parameter default to 0,
it'll use port 465.

I tested with my ISP.

Using port 465, it failed.

Using the default, it succeeded.

So, I changed the code how you said, but still not working.


Code:

import smtplib

fromaddr = 'mksfjnsfji4433j4...@bk.ru <mailto:mksfjnsfji4433j4...@bk.ru>'
toaddrs = ['mksfjnsfji4433j4...@bk.ru <mailto:mksfjnsfji4433j4...@bk.ru>']

msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs)))

msg = msg + 'test'

server = smtplib.SMTP('smtp.mail.ru <http://smtp.mail.ru>')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()


Traceback:

send: 'ehlo [192.168.0.107]\r\n'
reply: b'250-smtp15.mail.ru <http://250-smtp15.mail.ru>\r\n'
reply: b'250-SIZE 73400320\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-AUTH PLAIN LOGIN XOAUTH2\r\n'
reply: b'250 STARTTLS\r\n'
reply: retcode (250); Msg: b'smtp15.mail.ru 
<http://smtp15.mail.ru>\nSIZE 73400320\n8BITMIME\nPIPELINING\nAUTH 
PLAIN LOGIN XOAUTH2\nSTARTTLS'
send: 'mail FROM:<mailto:mksfjnsfji4433j4...@bk.ru>> size=70\r\n'

reply: b'250 2.0.0 OK\r\n'
reply: retcode (250); Msg: b'2.0.0 OK'
send: 'rcpt TO:<mailto:mksfjnsfji4433j4...@bk.ru>>\r\n'
reply: b'550 SMTP is available only with SSL or TLS connection 
enabled.\r\n'
reply: retcode (550); Msg: b'SMTP is available only with SSL or TLS 
connection enabled.'

send: 'rset\r\n'
Traceback (most recent call last):
File ".\test.py", line 13, in 
server.sendmail(fromaddr, toaddrs, msg)
File "C:\Python34\lib\smtplib.py", line 793, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'mksfjnsfji4433j4...@bk.ru 
<mailto:mksfjnsfji4433j4...@bk.ru>': (550, b'SMTP is available only 
with SSL or TLS connection e

nabled.')}



Try with the TLS:


...
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.sendmail(
--
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib not working as expected

2014-12-26 Thread Juan Christian
On Fri Dec 26 2014 at 11:07:30 PM MRAB  wrote:
According to the docs, if you let the port parameter default to 0,
it'll use port 465.

I tested with my ISP.

Using port 465, it failed.

Using the default, it succeeded.

So, I changed the code how you said, but still not working.


Code:

import smtplib

fromaddr = 'mksfjnsfji4433j4...@bk.ru'
toaddrs = ['mksfjnsfji4433j4...@bk.ru']

msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs)))

msg = msg + 'test'

server = smtplib.SMTP('smtp.mail.ru')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()


Traceback:

send: 'ehlo [192.168.0.107]\r\n'
reply: b'250-smtp15.mail.ru\r\n'
reply: b'250-SIZE 73400320\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-PIPELINING\r\n'
reply: b'250-AUTH PLAIN LOGIN XOAUTH2\r\n'
reply: b'250 STARTTLS\r\n'
reply: retcode (250); Msg: b'smtp15.mail.ru\nSIZE
73400320\n8BITMIME\nPIPELINING\nAUTH PLAIN LOGIN XOAUTH2\nSTARTTLS'
send: 'mail FROM: size=70\r\n'
reply: b'250 2.0.0 OK\r\n'
reply: retcode (250); Msg: b'2.0.0 OK'
send: 'rcpt TO:\r\n'
reply: b'550 SMTP is available only with SSL or TLS connection enabled.\r\n'
reply: retcode (550); Msg: b'SMTP is available only with SSL or TLS
connection enabled.'
send: 'rset\r\n'
Traceback (most recent call last):
File ".\test.py", line 13, in 
server.sendmail(fromaddr, toaddrs, msg)
File "C:\Python34\lib\smtplib.py", line 793, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'mksfjnsfji4433j4...@bk.ru': (550, b'SMTP
is available only with SSL or TLS connection e
nabled.')}
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smtplib not working as expected

2014-12-26 Thread MRAB

On 2014-12-27 00:39, Juan Christian wrote:

I have the following test code:

import smtplib

fromaddr = 'mksfjnsfji4433j4...@bk.ru <mailto:mksfjnsfji4433j4...@bk.ru>'
toaddrs  = ['mksfjnsfji4433j4...@bk.ru <mailto:mksfjnsfji4433j4...@bk.ru>']

msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, ", ".join(toaddrs)))

msg = msg + 'test'

print("Message length is " + repr(len(msg)))

server = smtplib.SMTP('smtp.mail.ru <http://smtp.mail.ru>', 465)
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

And when I execute it, it keeps running forever and I don't get any
email. What's missing, what's wrong? The smtp server and port are
correct - https://help.mail.ru/enmail-help/mailer/popsmtp

I'm following this tutorial:https://docs.python.org/3/library/smtplib.html

Python 3.4.2


According to the docs, if you let the port parameter default to 0,
it'll use port 465.

I tested with my ISP.

Using port 465, it failed.

Using the default, it succeeded.

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


smtplib not working as expected

2014-12-26 Thread Juan Christian
I have the following test code:

import smtplib

fromaddr = 'mksfjnsfji4433j4...@bk.ru'
toaddrs  = ['mksfjnsfji4433j4...@bk.ru']

msg = ("From: %s\r\nTo: %s\r\n\r\n"
   % (fromaddr, ", ".join(toaddrs)))

msg = msg + 'test'

print("Message length is " + repr(len(msg)))

server = smtplib.SMTP('smtp.mail.ru', 465)
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

And when I execute it, it keeps running forever and I don't get any email.
What's missing, what's wrong? The smtp server and port are correct -
https://help.mail.ru/enmail-help/mailer/popsmtp

I'm following this tutorial:https://docs.python.org/3/library/smtplib.html

Python 3.4.2
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error importing smtplib

2012-11-19 Thread Eric Frederich
I can do this in stand alone programs because my code does the import and
calls the login function so I can control the order of things.
Unfortunately stand alone programs are not the only ways in which I am
using these Python bindings.

You can customize and extend this 3rd party application at various
extension points all of which are invoked after login.
We have a lot of extensions written in Python.

I guess I will have to back to the BAR vendor and ask if it is okay to
remove their old .so file.
Perhaps their code will just work with the newer 0.9.8e or perhaps they'll
have to relink or recompile.

On Fri, Nov 16, 2012 at 5:00 PM, Terry Reedy  wrote:

> [easy] Do the import before the function call, which is the proper order
> and the one that works.
>
> --
> Terry Jan Reedy
>
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error importing smtplib

2012-11-17 Thread Dieter Maurer
Eric Frederich  writes:

> ...
> So I'm guessing the problem is that after I log in, the process has a
> conflicting libssl.so file loaded.
> Then when I try to import smtplib it tries getting things from there and
> that is where the errors are coming from.
>
> The question now is how do I fix this?

Likely, you must relink the shared object containing
your "FOO_login". When its current version was linked,
the (really) old "libssl" has been current and the version was linked
against it.
As the binary objects for your shared object might depend on the old
version, it is best, to not only relink but to recompile it as well.

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


Re: error importing smtplib

2012-11-16 Thread Terry Reedy

On 11/16/2012 2:37 PM, Eric Frederich wrote:

So I inspected the process through /proc//maps
That seemed to show what libraries had been loaded (though there is
probably an easier way to do this).



In any case, I found that if I import smtplib before logging in I see
these get loaded...

 /opt/foo/python27/lib/python2.7/lib-dynload/_ssl.so
 /lib64/libssl.so.0.9.8e

Then after logging in, I see this other .so get loaded...

 /opt/bar/lib64/libssl.so.0.9.7


That version appears to be about a decade old. Why is bar using it?


So that is what happens when when things are well and I don't get any
error messages.
However, when I do the log in first I see the /opt/bar .so file loaded first

 /opt/bar/lib64/libssl.so.0.9.7

Then after importing smtplib I see the other two show up...

 /opt/foo/python27/lib/python2.7/lib-dynload/_ssl.so
 /lib64/libssl.so.0.9.8e


What I know is that hashlib.py imports _hashlib (compilied .c) and that 
the latter wraps libssl, or calls _ssl.so which wraps libssl. In *nix 
this is expected to already be on the system, so in not distributed with 
python. Furthermore, hashlib requires a version recent enough to have 
the latest (best) hash functions. I suspect decade-old 9.9.7 does not 
qualify.


What I don't know is how .so loading and linking works. It seems that 
two version get loaded but linking gets messed up. This reminds me of 
'dll hell' on Windows ;-). I don't know either if modifying the loading 
of ...9.7 in for or bar code could do anything.



So I'm guessing the problem is that after I log in, the process has
a conflicting libssl.so file loaded.
Then when I try to import smtplib it tries getting things from there and
that is where the errors are coming from.

The question now is how do I fix this?


[easy] Do the import before the function call, which is the proper order 
and the one that works.


Remove ...9.7 from bar/lib64/ and have bar use the up-to-date system 
version, like python does. An alternative is to replace ...9.7 with a 
duplicate ...9.8e (and probably better, only load it if there is no 
system version).



What else should I be checking?


Thinking more, you can look at sys.modules, but this does not have any 
info about non-module libraries wrapped by modules, even if the latter 
are C-coded.


--
Terry Jan Reedy

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


Re: error importing smtplib

2012-11-16 Thread Dieter Maurer
Eric Frederich  writes:

> I created some bindings to a 3rd party library.
> I have found that when I run Python and import smtplib it works fine.
> If I first log into the 3rd party application using my bindings however I
> get a bunch of errors.
>
> What do you think this 3rd party login could be doing that would affect the
> ability to import smtp lib.
>
> Any suggestions for debugging this further.  I am lost.
>
> This works...
>
> import smtplib
> FOO_login()
>
> This doesn't...
>
> FOO_login()
> import smtplib
>
> Errors.
>
>>>> import smtplib
> ERROR:root:code for hash sha224 was not found.
> Traceback (most recent call last):
>   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
> globals()[__func_name] = __get_hash(__func_name)
>   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
> __get_openssl_constructor
> return __get_builtin_constructor(name)
>   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
> __get_builtin_constructor
> raise ValueError('unsupported hash type %s' % name)
> ValueError: unsupported hash type sha224

>From the error, I suppose it does something bad
for hash registries.

When I have analysed problems with "hashlib" (some time ago,
my memory may not be completely trustworthy), I got the
impression that "hashlib" essentially delegates to the
"openssl" libraries for the real work and especially
the supported hash types. Thus, I suspect that
your "FOO_login()" does something which confuses "openssl".
One potential reason could be that it loads a bad version
of an "openssl" shared library.

I would use the "trace" (shell) command to find out what operating system
calls are executed during "FOO_login()", hoping that one of them
give me a clue.

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


Re: error importing smtplib

2012-11-16 Thread Eric Frederich
So I inspected the process through /proc//maps
That seemed to show what libraries had been loaded (though there is
probably an easier way to do this).

In any case, I found that if I import smtplib before logging in I see these
get loaded...

/opt/foo/python27/lib/python2.7/lib-dynload/_ssl.so
/lib64/libssl.so.0.9.8e

Then after logging in, I see this other .so get loaded...

/opt/bar/lib64/libssl.so.0.9.7

So that is what happens when when things are well and I don't get any error
messages.
However, when I do the log in first I see the /opt/bar .so file loaded first

/opt/bar/lib64/libssl.so.0.9.7

Then after importing smtplib I see the other two show up...

/opt/foo/python27/lib/python2.7/lib-dynload/_ssl.so
/lib64/libssl.so.0.9.8e

So I'm guessing the problem is that after I log in, the process has a
conflicting libssl.so file loaded.
Then when I try to import smtplib it tries getting things from there and
that is where the errors are coming from.

The question now is how do I fix this?




On Thu, Nov 15, 2012 at 4:37 PM, Terry Reedy  wrote:

> On 11/15/2012 1:48 PM, Eric Frederich wrote:
>
>> Thanks for the idea.
>> sys.path was the same before and after the login
>>
>
> Too bad. That seems to be a typical cause of import failure.
>
>
>  What else should I be checking?
>>
>
> No idea. You are working beyond my knowledge. But I might either look at
> the foo-login code carefully, or disable (comment out) parts of it to see
> what makes the import fail.
>
>
> --
> Terry Jan Reedy
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error importing smtplib

2012-11-15 Thread Terry Reedy

On 11/15/2012 1:48 PM, Eric Frederich wrote:

Thanks for the idea.
sys.path was the same before and after the login


Too bad. That seems to be a typical cause of import failure.


What else should I be checking?


No idea. You are working beyond my knowledge. But I might either look at 
the foo-login code carefully, or disable (comment out) parts of it to 
see what makes the import fail.


--
Terry Jan Reedy

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


Re: error importing smtplib

2012-11-15 Thread Eric Frederich
Sorry, only saw your first response, didn't see the others.

I compiled Python 2.7.2 myself with --enable-shared
To create standalone applications that interact with this 3rd party program
your main C file instead of having a "main" function has a FOO_user_main
function.
When you link your program you link against a provided foo_main.o file.

My python executable (called FOO_user_main) was created from python.c but
with main replaced with FOO_user_main no other differences.

I have been using this type of installation for a couple of years and
everything works fine.

I only get these errors/warnings on one environment out of 10 or so
development and qa machines.

Any help trying to figure out what is different before and after the login
would be appreciated.
Is there some place in /proc I could look to see what happened?

Thanks,
~Eric


On Thu, Nov 15, 2012 at 11:57 AM, Terry Reedy  wrote:

> On 11/15/2012 9:38 AM, Eric Frederich wrote:
>
>> Hello,
>>
>> I created some bindings to a 3rd party library.
>> I have found that when I run Python and import smtplib it works fine.
>> If I first log into the 3rd party application using my bindings however
>> I get a bunch of errors.
>>
>> What do you think this 3rd party login could be doing that would affect
>> the ability to import smtp lib.
>>
>
> I don't know what 'login' actually means,...
>
>
>  This works...
>>
>> import smtplib
>> FOO_login()
>>
>> This doesn't...
>>
>> FOO_login()
>> import smtplib
>>
>
> but my first guess is that FOO_login alters the module search path so that
> at least one of smtplib, hashlib, or the _xxx modules imported by hashlib
> is being imported from a different place. To check that
>
> import sys
> before = sys.path
> FOO_login()
> print sys.path==before
>
> Similar code can check anything else accessible through sys.
>
>
>  Errors.
>>
>>  >>> import smtplib
>> ERROR:root:code for hash sha224 was not found.
>>
>
> I am puzzled by this line before the traceback. I cannot find 'ERROR' in
> either smtplib or hashlib.
>
>
>  Traceback (most recent call last):
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 139, in
>> 
>>  globals()[__func_name] = __get_hash(__func_name)
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 103, in
>> __get_openssl_constructor
>>  return __get_builtin_constructor(**name)
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 91, in
>> __get_builtin_constructor
>>  raise ValueError('unsupported hash type %s' % name)
>> ValueError: unsupported hash type sha224
>>
> [snip similar messages]
>
> It is also unusual to get multiple tracebacks. *Exactly* how are you
> running python and is 2.7 what you intend to run?
>
> --
> Terry Jan Reedy
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: error importing smtplib

2012-11-15 Thread Eric Frederich
Thanks for the idea.
sys.path was the same before and after the login

What else should I be checking?

On Thu, Nov 15, 2012 at 11:57 AM, Terry Reedy  wrote:

> On 11/15/2012 9:38 AM, Eric Frederich wrote:
>
>> Hello,
>>
>> I created some bindings to a 3rd party library.
>> I have found that when I run Python and import smtplib it works fine.
>> If I first log into the 3rd party application using my bindings however
>> I get a bunch of errors.
>>
>> What do you think this 3rd party login could be doing that would affect
>> the ability to import smtp lib.
>>
>
> I don't know what 'login' actually means,...
>
>
>  This works...
>>
>> import smtplib
>> FOO_login()
>>
>> This doesn't...
>>
>> FOO_login()
>> import smtplib
>>
>
> but my first guess is that FOO_login alters the module search path so that
> at least one of smtplib, hashlib, or the _xxx modules imported by hashlib
> is being imported from a different place. To check that
>
> import sys
> before = sys.path
> FOO_login()
> print sys.path==before
>
> Similar code can check anything else accessible through sys.
>
>
>  Errors.
>>
>>  >>> import smtplib
>> ERROR:root:code for hash sha224 was not found.
>>
>
> I am puzzled by this line before the traceback. I cannot find 'ERROR' in
> either smtplib or hashlib.
>
>
>  Traceback (most recent call last):
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 139, in
>> 
>>  globals()[__func_name] = __get_hash(__func_name)
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 103, in
>> __get_openssl_constructor
>>  return __get_builtin_constructor(**name)
>>File "/opt/foo/python27/lib/**python2.7/hashlib.py", line 91, in
>> __get_builtin_constructor
>>  raise ValueError('unsupported hash type %s' % name)
>> ValueError: unsupported hash type sha224
>>
> [snip similar messages]
>
> It is also unusual to get multiple tracebacks. *Exactly* how are you
> running python and is 2.7 what you intend to run?
>
> --
> Terry Jan Reedy
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting "empty" attachment with smtplib

2012-11-15 Thread Tobiah

I can already say that "smtplib" is not to blame. It is (mostly) unconcerned
with the internal structure of the message -- and by itself
will not empty attachments.


On the advice of a co-worker, I tried using web2py's gluon.tools.Mail.  It
was easier to accomplish the attachment, and Thunderbird opened the .pdf
just fine.

Thanks for the suggestions.

Tobiah

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


Re: error importing smtplib

2012-11-15 Thread Terry Reedy

On 11/15/2012 9:38 AM, Eric Frederich wrote:

Hello,

I created some bindings to a 3rd party library.
I have found that when I run Python and import smtplib it works fine.
If I first log into the 3rd party application using my bindings however
I get a bunch of errors.

What do you think this 3rd party login could be doing that would affect
the ability to import smtp lib.


I don't know what 'login' actually means,...


This works...

import smtplib
FOO_login()

This doesn't...

FOO_login()
import smtplib


but my first guess is that FOO_login alters the module search path so 
that at least one of smtplib, hashlib, or the _xxx modules imported by 
hashlib is being imported from a different place. To check that


import sys
before = sys.path
FOO_login()
print sys.path==before

Similar code can check anything else accessible through sys.


Errors.

 >>> import smtplib
ERROR:root:code for hash sha224 was not found.


I am puzzled by this line before the traceback. I cannot find 'ERROR' in 
either smtplib or hashlib.



Traceback (most recent call last):
   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
 globals()[__func_name] = __get_hash(__func_name)
   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
__get_openssl_constructor
 return __get_builtin_constructor(name)
   File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
 raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224

[snip similar messages]

It is also unusual to get multiple tracebacks. *Exactly* how are you 
running python and is 2.7 what you intend to run?


--
Terry Jan Reedy

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


error importing smtplib

2012-11-15 Thread Eric Frederich
Hello,

I created some bindings to a 3rd party library.
I have found that when I run Python and import smtplib it works fine.
If I first log into the 3rd party application using my bindings however I
get a bunch of errors.

What do you think this 3rd party login could be doing that would affect the
ability to import smtp lib.

Any suggestions for debugging this further.  I am lost.

This works...

import smtplib
FOO_login()

This doesn't...

FOO_login()
import smtplib

Errors.

>>> import smtplib
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
__get_openssl_constructor
return __get_builtin_constructor(name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
__get_openssl_constructor
return __get_builtin_constructor(name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
__get_openssl_constructor
return __get_builtin_constructor(name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 139, in 
globals()[__func_name] = __get_hash(__func_name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 103, in
__get_openssl_constructor
return __get_builtin_constructor(name)
  File "/opt/foo/python27/lib/python2.7/hashlib.py", line 91, in
__get_builtin_constructor
raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha512
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting "empty" attachment with smtplib

2012-11-14 Thread Dieter Maurer
Tobiah  writes:

> I just found out that the attachment works fine
> when I read the mail from the gmail website.  Thunderbird
> complains that the attachment is empty.

The MIME standard (a set of RFCs) specifies how valid messages
with attachments should look like.

Fetch the mail (unprocessed if possible) and look at its
structure. If it is conformant to the MIME standard, then
"Thunderbird" made a mistake; otherwise, something went wrong
with the message construction.

I can already say that "smtplib" is not to blame. It is (mostly) unconcerned
with the internal structure of the message -- and by itself
will not empty attachments.

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


Re: Getting "empty" attachment with smtplib

2012-11-14 Thread Tobiah

I just found out that the attachment works fine
when I read the mail from the gmail website.  Thunderbird
complains that the attachment is empty.

Thanks,

Toby

On 11/14/2012 09:51 AM, Tobiah wrote:

I've been sending an email blast out with smtplib and
it's been working fine. I'm attaching an html doc with

msg.attach(MIMEText(email, 'html'))

and it displays fine. Now I need to attach a .pdf
doc, but Thunderbird complains that the attachment
is empty. When I view the source of the email, the
headers look ok to me, and a large base64 looking
mess follows:

--===0152408622==
Content-Type: application/pdf
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="tics.pdf"

JVBERi0xLjYNJeLjz9MNCjE0IDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDExNzk1My9PIDE2L0Ug
MTEyNjE3L04gMS9UIDExNzY0My9IIFsgNjA2IDI1M10+Pg1lbmRvYmoNICAgICAgICAgICAgICAg
DQo2MSAwIG9iag08PC9EZWNvZGVQYXJtczw8L0NvbHVtbnMgNS9QcmVkaWN0b3IgMTI+Pi9GaWx0
ZXIvRmxhdGVEZWNvZGUvSURbPDg4RkMxMTM2QjQ3RDhEQzRFMjkxQkEzRDJGNEIyODBBPjxGRTNC
RkM3MjNFMDg3QzRCQUEyNTUzMkM5NEI5QjNCOT5dL0luZGV4WzE0IDc4XS9JbmZvIDEzIDAgUi9M

and so on. I've tried a few recipes, and this is the one I'm trying now:

pdf = MIMEApplication(pdf_data, 'pdf')
pdf.add_header('Content-Disposition','attachment', filename = 'tics.pdf')
msg.attach(pdf)

Any help is appreciated. Also, if anyone has a working recipe, I'd like to
see it.

Thanks!

Tobiah


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


Re: smtplib is broken when using TLS

2011-05-19 Thread Giampaolo Rodolà
Please file a ticket on:
http://bugs.python.org/

Regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/

2011/5/17 nirinA raseliarison :
> i think this has the same origin as the ftplib test failure.
>
> Python 3.2.1rc1 (default, May 17 2011, 22:01:34)
> [GCC 4.6.0] on linux2
> Type "copyright", "credits" or "license()" for more information.

  RESTART
 

>
> send: 'ehlo [127.0.0.1]\r\n'
> reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n'
> reply: b'250-SIZE 35882577\r\n'
> reply: b'250-8BITMIME\r\n'
> reply: b'250-STARTTLS\r\n'
> reply: b'250 ENHANCEDSTATUSCODES\r\n'
> reply: retcode (250); Msg: b'mx.google.com at your service,
> [41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES'
> send: 'STARTTLS\r\n'
> reply: b'220 2.0.0 Ready to start TLS\r\n'
> reply: retcode (220); Msg: b'2.0.0 Ready to start TLS'
> Traceback (most recent call last):
>    File "/root/template_mail_text.py", line 49, in 
>      server.starttls()
>    File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls
>      self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
>    File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket
>      ciphers=ciphers)
>    File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__
>      raise x
>    File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__
>      self.do_handshake()
>    File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake
>      self._sslobj.do_handshake()
> ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL
> routines:SSL3_READ_BYTES:sslv3 alert bad record mac
>
>
> --
> nirinA
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


smtplib is broken when using TLS

2011-05-17 Thread nirinA raseliarison

i think this has the same origin as the ftplib test failure.

Python 3.2.1rc1 (default, May 17 2011, 22:01:34)
[GCC 4.6.0] on linux2
Type "copyright", "credits" or "license()" for more information.
 RESTART  





send: 'ehlo [127.0.0.1]\r\n'
reply: b'250-mx.google.com at your service, [41.188.13.184]\r\n'
reply: b'250-SIZE 35882577\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-STARTTLS\r\n'
reply: b'250 ENHANCEDSTATUSCODES\r\n'
reply: retcode (250); Msg: b'mx.google.com at your service,
[41.188.13.184]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES'
send: 'STARTTLS\r\n'
reply: b'220 2.0.0 Ready to start TLS\r\n'
reply: retcode (220); Msg: b'2.0.0 Ready to start TLS'
Traceback (most recent call last):
File "/root/template_mail_text.py", line 49, in 
  server.starttls()
File "/usr/local/lib/python3.2/smtplib.py", line 649, in starttls
  self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
File "/usr/local/lib/python3.2/ssl.py", line 509, in wrap_socket
  ciphers=ciphers)
File "/usr/local/lib/python3.2/ssl.py", line 266, in __init__
  raise x
File "/usr/local/lib/python3.2/ssl.py", line 262, in __init__
  self.do_handshake()
File "/usr/local/lib/python3.2/ssl.py", line 441, in do_handshake
  self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:392: error:140943FC:SSL
routines:SSL3_READ_BYTES:sslv3 alert bad record mac


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


Re: smtplib with Google

2010-09-13 Thread narke
On 2010-09-13, member thudfoo  wrote:
> On Mon, Sep 13, 2010 at 9:20 AM, narke  wrote:
>>
>> Hi,
>>
>> Can anyone please show me a workable example that can let me use
>> google's smtp server to send out a message?  Thanks.
>>
>
> Go here:
>
>   http://code.activestate.com/recipes/langs/python/
>
> and search for this
>
>  gmail

Thanks!

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke


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


Re: smtplib with Google

2010-09-13 Thread member thudfoo
On Mon, Sep 13, 2010 at 9:20 AM, narke  wrote:
>
> Hi,
>
> Can anyone please show me a workable example that can let me use
> google's smtp server to send out a message?  Thanks.
>

Go here:

  http://code.activestate.com/recipes/langs/python/

and search for this

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


smtplib with Google

2010-09-13 Thread narke
Hi,

Can anyone please show me a workable example that can let me use
google's smtp server to send out a message?  Thanks.

-- 
Life is the only flaw in an otherwise perfect nonexistence
   -- Schopenhauer

narke


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


Re: mail sending -- smtplib

2010-09-07 Thread Kurian Thayil
Got it fixed. It was a very silly mistake. mssg variable had each line with
indent. Removed the indent and it worked.

Regards,

Kurian Thayil.

On Tue, Sep 7, 2010 at 9:57 AM, Kurian Thayil wrote:

> Hi All,
>
> I am a newbie in python. Just 2-3 days old wanting to learn this amazing
> programming language. I was trying to send mails using smtplib module, so
> did some google and found a code snippet. The mail gets sent, but doesn't
> come in the right format when a for-loop is introduced (Not MIME standard?).
> Without the for-loop the script works fine. Can anyone advice?
> *
> #!/usr/bin/env python
>
> import smtplib
>
> for i in range(1,5):
> print "I is ",i
> fromaddr='kurianmtha...@gmail.com'
> toaddr='kurianmtha...@gmail.com'
> print toaddr
> mssg="""From: Kurian Thayil 
> To: Kurian Thayil 
> MIME-Version: 1.0
> Content-type: text/html
> Subject: 12345 -- Reloaded :)
>
> Hey dude.. how are you
>
> 
> Regards,
> 
> Kurian
> """
> print "message is ",mssg
>
> smail=smtplib.SMTP('smtp.gmail.com',587)
>
> smail.ehlo()
> smail.starttls()
> smail.ehlo()
> smail.login(fromaddr,'***')
>
> smail.sendmail(fromaddr,toaddr,mssg)
> print "Over"
> *
>
> Regards,
>
> Kurian Thayil.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


mail sending -- smtplib

2010-09-06 Thread Kurian Thayil
Hi All,

I am a newbie in python. Just 2-3 days old wanting to learn this amazing
programming language. I was trying to send mails using smtplib module, so
did some google and found a code snippet. The mail gets sent, but doesn't
come in the right format when a for-loop is introduced (Not MIME standard?).
Without the for-loop the script works fine. Can anyone advice?
*
#!/usr/bin/env python

import smtplib

for i in range(1,5):
print "I is ",i
fromaddr='kurianmtha...@gmail.com'
toaddr='kurianmtha...@gmail.com'
print toaddr
mssg="""From: Kurian Thayil 
To: Kurian Thayil 
MIME-Version: 1.0
Content-type: text/html
Subject: 12345 -- Reloaded :)

Hey dude.. how are you


Regards,

Kurian
"""
print "message is ",mssg

smail=smtplib.SMTP('smtp.gmail.com',587)

smail.ehlo()
smail.starttls()
smail.ehlo()
smail.login(fromaddr,'***')

smail.sendmail(fromaddr,toaddr,mssg)
print "Over"
*

Regards,

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


Re: Get authentication error while using 'smtplib'

2010-08-22 Thread Mahmood Naderan
Well, login plain did the job:
 
session = smtplib.SMTP(smtpserver)
session.ehlo()
session.esmtp_features["auth"] = "LOGIN PLAIN"if AUTHREQUIRED:
   session.login(smtpuser, smtppass)

 
// Naderan *Mahmood;





From: Mahmood Naderan 
To: python mailing list 
Sent: Fri, August 20, 2010 6:13:20 PM
Subject: Get authentication error while using 'smtplib'


I have this script to send an email via SMTP:
import smtplib
smtpserver = 'smtp.server.com'
AUTHREQUIRED = 1# if you need to use SMTP AUTH set to 1
smtpuser = "username"# for SMTP AUTH, set SMTP username here
smtppass = "password"# for SMTP AUTH, set SMTP password here
RECIPIENTS ='recipi...@server.com'
SENDER = 'sen...@server.com'
mssg = open('filename.txt', 'r').read()
session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
   session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
After running the script I get this error:
 
Traceback (most recent call last):
  File "my_mail.py", line 14, in 
    session.login(smtpuser, smtppass)
  File "/usr/lib/python2.6/smtplib.py", line 589, in login
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, '5.7.0 Error: authentication failed: 
authentication failure')

However there is no problem with my user/pass because I can login to my mail 
account.

Thanks for any idea. 
// Naderan *Mahmood; 


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


Get authentication error while using 'smtplib'

2010-08-20 Thread Mahmood Naderan
I have this script to send an email via SMTP:
import smtplib
smtpserver = 'smtp.server.com'
AUTHREQUIRED = 1# if you need to use SMTP AUTH set to 1
smtpuser = "username"# for SMTP AUTH, set SMTP username here
smtppass = "password"# for SMTP AUTH, set SMTP password here
RECIPIENTS ='recipi...@server.com'
SENDER = 'sen...@server.com'
mssg = open('filename.txt', 'r').read()
session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
   session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
After running the script I get this error:
 
Traceback (most recent call last):
  File "my_mail.py", line 14, in 
    session.login(smtpuser, smtppass)
  File "/usr/lib/python2.6/smtplib.py", line 589, in login
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, '5.7.0 Error: authentication failed: 
authentication failure')

However there is no problem with my user/pass because I can login to my mail 
account.

Thanks for any idea. 
// Naderan *Mahmood; 


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


Re: Problem w/ smtplib

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 1:16 PM, Kev Dwyer  wrote:

>
> 2009/11/21 Victor Subervi 
>
> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote:
>>
>>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>>>
>>> Hello Victor,
>>>
>>> The information that you have sent comes from the client side of the
>>> transaction, so it isn't possible to tell why the server disconnected.
>>> Assuming that there is an SMTP server listening on port 25, you need to
>>> check the SMTP server logs.
>>
>>
>> There wasn't anything in /var/log/maillog. Is that where I should have
>> checked?
>>
>>
>>> You might need to crank up the logging to
>>> get useful output.
>>>
>>
>> How?
>> Look at the output below:
>>
>> [r...@13gems stcroixresort]# netstat -tulp
>> Active Internet connections (only servers)
>> Proto Recv-Q Send-Q Local Address   Foreign
>> Address State   PID/Program name
>> tcp0  0 *:mysql
>> *:* LISTEN  24488/mysqld
>> tcp0  0 *:pop3
>> *:* LISTEN  5278/tcpserver
>> tcp0  0 *:ftp
>> *:* LISTEN  26564/vsftpd
>> tcp0  0 localhost.localdomai:domain
>> *:* LISTEN  11845/named
>> tcp0  0 *:smtp
>> *:* LISTEN  5274/tcpserver
>> tcp0  0 localhost.localdomain:rndc
>> *:* LISTEN  11845/named
>> tcp0  0 *:http
>> *:* LISTEN  5201/httpd
>> tcp0  0 localhost:domain
>> *:* LISTEN  11845/named
>> tcp0  0 *:ssh
>> *:* LISTEN  15509/sshd
>> tcp0  0 localhost:rndc
>> *:* LISTEN  11845/named
>> udp0  0 localhost.locald:domain
>> *:* 11845/named
>> udp0  0 localhost:domain
>> *:* 11845/named
>> [r...@13gems stcroixresort]# qmailctl stat
>> /service/qmail-send: up (pid 5266) 594565 seconds
>> /service/qmail-send/log: up (pid 5271) 594565 seconds
>> /service/qmail-smtpd: up (pid 5274) 594565 seconds
>> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds
>> /service/qmail-pop3d: up (pid 5278) 594565 seconds
>> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds
>> messages in queue: 0
>> messages in queue but not yet preprocessed: 0
>>
>> Please advise.
>> TIA,
>> V
>>
>
> Hello Victor,
>
>  I'm afraid I don't know much about mail servers, you need to check the
> server docs or ask on a qmail mailing list.
>
> If you really think this is a python issue, then you could try:
> >>> import smtplib
> >>> server = smtplib.SMTP()
> >>> server.set_debuglevel(1)
> >>> server.connect()
> connect: ('localhost', 25)
> connect: (25, 'localhost')
> reply: '220 pluto.site ESMTP Postfix\r\n'
> reply: retcode (220); Msg: pluto.site ESMTP Postfix
> connect: pluto.site ESMTP Postfix
> (220, 'pluto.site ESMTP Postfix')
> >>> server.quit()
> send: 'quit\r\n'
> reply: '221 2.0.0 Bye\r\n'
> reply: retcode (221); Msg: 2.0.0 Bye
> (221, '2.0.0 Bye')
>
>
> and see if there are any error messages/tracebacks in the output; but if
> you still get a disconnect exception then it's unlikely that this is a
> python issue.
>

Thank you. Yes, there was an error.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem w/ smtplib

2009-11-21 Thread Kev Dwyer
2009/11/21 Victor Subervi 

> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote:
>
>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>>
>> Hello Victor,
>>
>> The information that you have sent comes from the client side of the
>> transaction, so it isn't possible to tell why the server disconnected.
>> Assuming that there is an SMTP server listening on port 25, you need to
>> check the SMTP server logs.
>
>
> There wasn't anything in /var/log/maillog. Is that where I should have
> checked?
>
>
>> You might need to crank up the logging to
>> get useful output.
>>
>
> How?
> Look at the output below:
>
> [r...@13gems stcroixresort]# netstat -tulp
> Active Internet connections (only servers)
> Proto Recv-Q Send-Q Local Address   Foreign Address
> State   PID/Program name
> tcp0  0 *:mysql *:*
> LISTEN  24488/mysqld
> tcp0  0 *:pop3  *:*
> LISTEN  5278/tcpserver
> tcp0  0 *:ftp   *:*
> LISTEN  26564/vsftpd
> tcp0  0 localhost.localdomai:domain *:*
> LISTEN  11845/named
> tcp0  0 *:smtp  *:*
> LISTEN  5274/tcpserver
> tcp0  0 localhost.localdomain:rndc  *:*
> LISTEN  11845/named
> tcp0  0 *:http  *:*
> LISTEN  5201/httpd
> tcp0  0 localhost:domain*:*
> LISTEN  11845/named
> tcp0  0 *:ssh   *:*
> LISTEN  15509/sshd
> tcp0  0 localhost:rndc  *:*
> LISTEN  11845/named
> udp0  0 localhost.locald:domain
> *:* 11845/named
> udp0  0 localhost:domain
> *:* 11845/named
> [r...@13gems stcroixresort]# qmailctl stat
> /service/qmail-send: up (pid 5266) 594565 seconds
> /service/qmail-send/log: up (pid 5271) 594565 seconds
> /service/qmail-smtpd: up (pid 5274) 594565 seconds
> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds
> /service/qmail-pop3d: up (pid 5278) 594565 seconds
> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds
> messages in queue: 0
> messages in queue but not yet preprocessed: 0
>
> Please advise.
> TIA,
> V
>

Hello Victor,

 I'm afraid I don't know much about mail servers, you need to check the
server docs or ask on a qmail mailing list.

If you really think this is a python issue, then you could try:
>>> import smtplib
>>> server = smtplib.SMTP()
>>> server.set_debuglevel(1)
>>> server.connect()
connect: ('localhost', 25)
connect: (25, 'localhost')
reply: '220 pluto.site ESMTP Postfix\r\n'
reply: retcode (220); Msg: pluto.site ESMTP Postfix
connect: pluto.site ESMTP Postfix
(220, 'pluto.site ESMTP Postfix')
>>> server.quit()
send: 'quit\r\n'
reply: '221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: 2.0.0 Bye
(221, '2.0.0 Bye')


and see if there are any error messages/tracebacks in the output; but if you
still get a disconnect exception then it's unlikely that this is a python
issue.

Cheers,

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


Re: Problem w/ smtplib

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer  wrote:

> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>
> Hello Victor,
>
> The information that you have sent comes from the client side of the
> transaction, so it isn't possible to tell why the server disconnected.
> Assuming that there is an SMTP server listening on port 25, you need to
> check the SMTP server logs.


There wasn't anything in /var/log/maillog. Is that where I should have
checked?


> You might need to crank up the logging to
> get useful output.
>

How?
Look at the output below:

[r...@13gems stcroixresort]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address
State   PID/Program name
tcp0  0 *:mysql *:*
LISTEN  24488/mysqld
tcp0  0 *:pop3  *:*
LISTEN  5278/tcpserver
tcp0  0 *:ftp   *:*
LISTEN  26564/vsftpd
tcp0  0 localhost.localdomai:domain *:*
LISTEN  11845/named
tcp0  0 *:smtp  *:*
LISTEN  5274/tcpserver
tcp0  0 localhost.localdomain:rndc  *:*
LISTEN  11845/named
tcp0  0 *:http  *:*
LISTEN  5201/httpd
tcp0  0 localhost:domain*:*
LISTEN  11845/named
tcp0  0 *:ssh   *:*
LISTEN  15509/sshd
tcp0  0 localhost:rndc  *:*
LISTEN  11845/named
udp0  0 localhost.locald:domain
*:* 11845/named
udp0  0 localhost:domain
*:* 11845/named
[r...@13gems stcroixresort]# qmailctl stat
/service/qmail-send: up (pid 5266) 594565 seconds
/service/qmail-send/log: up (pid 5271) 594565 seconds
/service/qmail-smtpd: up (pid 5274) 594565 seconds
/service/qmail-smtpd/log: up (pid 5276) 594565 seconds
/service/qmail-pop3d: up (pid 5278) 594565 seconds
/service/qmail-pop3d/log: up (pid 5279) 594565 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0

Please advise.
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem w/ smtplib

2009-11-21 Thread Kev Dwyer
On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:

Hello Victor,

The information that you have sent comes from the client side of the 
transaction, so it isn't possible to tell why the server disconnected.  
Assuming that there is an SMTP server listening on port 25, you need to 
check the SMTP server logs.  You might need to crank up the logging to 
get useful output.  

If the information that you pasted in comes from a Django traceback then 
you could check the Django page on e-mail at 
http://docs.djangoproject.com/en/dev/topics/email/#topics-email
(dev version, you might need to view an older version).

Cheers,

Kev

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


Problem w/ smtplib

2009-11-21 Thread Victor Subervi
Hi;
I get the following error:

 /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py52
   session.sendmail(clientEmail, ourEmail1, header+msg)
53 #  session.sendmail(clientEmail, ourEmail2, header+msg)
54
55 mailSpreadsheet()
56
 *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* = , smtplib.*SMTP* = 
 /usr/lib64/python2.4/smtplib.py in *__init__*(self=,
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* = , self.*
connect* = >, *host* =
'localhost', *port* = 0   /usr/lib64/python2.4/smtplib.py in
*connect*(self=, 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* =
, self.*getreply* = >   /usr/lib64/python2.4/smtplib.py in
*getreply*(self=)   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* = *
SMTPServerDisconnected*: Connection unexpectedly closed
  args = ('Connection unexpectedly closed',)

Why did this connection close? How do I fix it? I tried commenting out the
authentication line. I have imported smtplib.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib upload progress

2009-10-19 Thread Gabriel Genellina
En Mon, 19 Oct 2009 19:33:50 -0300, Guyon Morée   
escribió:



I wanted to use smtplib to send a bunch of files. All good, except I
cant monitor the upload progress as far as I can see.

So I monkey patched the SMTP.sendall method, which chops up the data
and keeps calling a provided callback for every chunk of data sent.

This feels kind of dirty and I was wondering what my other options are
to tackle this seemingly simple problem.


(there is no sendall method in SMTP, but send)
Looks like there is no other way... perhaps I'd have overriden data()  
instead of send(), but it's as dirty as yours, one has to duplicate the  
original code.
I don't know how often the need arises or how useful would this be to  
others, but you could submit a patch to http://bugs.python.org/


--
Gabriel Genellina

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


Re: smtplib send mail dns resolve problem

2009-10-19 Thread 星星
On 10月19日, 下午11时05分, "Gabriel Genellina" 
wrote:
> En Mon, 19 Oct 2009 05:44:14 -0200, 星星   
> escribió:
>
> >     my email smtp server hostname can be parsed to 5 ips, for example:
> >     **
> >      my email smtp server hostname:  email-my.local.com
> >      ips through dns parse:
> >     1.1.1.1
> >     1.1.1.12
> >     1.1.13.1
> >     1.1.1.14
> >     1.1.1.15
> >     ******
>
> >     but when i send mail using smtplib, i was always using one ip, no
> > dns re-resolve happened, (for example: only use 1.1.1.12). I checked
> > smtplib src code, but i can't find anything strange;
>
> smtplib does not issue a dns query for a MX record, if that is what you  
> were expecting. In fact, the Python standard library does not contain any  
> module for DNS handling.
>
> >     for i in range(1000):
> >         server = smtplib.SMTP(host)
>
> Here, `host` is used directly -- whatever address gethostbyname returns.  
> If you want load balancing among the 5 addresses above, you'll have to do  
> it yourself:
>      host = random.choice(list_of_addresses)
>
> If you don't want to hardcode the addresses, there are a few libraries  
> that perform DNS queries in PyPI.
>
> --
> Gabriel Genellina

thanks very much! I tried your suggestion and it worked!

But I still wonder why gethostbyname returns the same address all the
time(maybe 5 times).
-- 
http://mail.python.org/mailman/listinfo/python-list


smtplib upload progress

2009-10-19 Thread Guyon Morée
Hi,

I wanted to use smtplib to send a bunch of files. All good, except I
cant monitor the upload progress as far as I can see.

So I monkey patched the SMTP.sendall method, which chops up the data
and keeps calling a provided callback for every chunk of data sent.

This feels kind of dirty and I was wondering what my other options are
to tackle this seemingly simple problem.

thanx,

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


Re: smtplib send mail dns resolve problem

2009-10-19 Thread Gabriel Genellina
En Mon, 19 Oct 2009 05:44:14 -0200, 星星   
escribió:



my email smtp server hostname can be parsed to 5 ips, for example:
**
 my email smtp server hostname:  email-my.local.com
 ips through dns parse:
1.1.1.1
1.1.1.12
1.1.13.1
1.1.1.14
1.1.1.15
**

but when i send mail using smtplib, i was always using one ip, no
dns re-resolve happened, (for example: only use 1.1.1.12). I checked
smtplib src code, but i can't find anything strange;


smtplib does not issue a dns query for a MX record, if that is what you  
were expecting. In fact, the Python standard library does not contain any  
module for DNS handling.



for i in range(1000):
server = smtplib.SMTP(host)


Here, `host` is used directly -- whatever address gethostbyname returns.  
If you want load balancing among the 5 addresses above, you'll have to do  
it yourself:

host = random.choice(list_of_addresses)

If you don't want to hardcode the addresses, there are a few libraries  
that perform DNS queries in PyPI.


--
Gabriel Genellina

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


smtplib send mail dns resolve problem

2009-10-19 Thread 星星
hello everyone,
 I am using smtplib to send email, and i meet such a problem:

my email smtp server hostname can be parsed to 5 ips, for example:
**
 my email smtp server hostname:  email-my.local.com
 ips through dns parse:
1.1.1.1
1.1.1.12
1.1.13.1
1.1.1.14
1.1.1.15
**

but when i send mail using smtplib, i was always using one ip, no
dns re-resolve happened, (for example: only use 1.1.1.12). I checked
smtplib src code, but i can't find anything strange;

here is my smtplib send mail client code:
 

for i in range(1000):
server = smtplib.SMTP(host)
try:
 server.sendmail(fromaddr, toaddr, msg)
except Exception, e:
 logger.warning('sendmail exception')
else:
 pass
finally:
 server.quit()
time.sleep(0.3)
 


Can anyone give some tips? Thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: redoing libgmail interface to "smtplib" blah?

2009-08-16 Thread Dave Angel

Dennis Lee Bieber wrote:

On Sat, 15 Aug 2009 23:14:39 -0600, John Haggerty 
declaimed the following in gmane.comp.python.general:

  

I did detect one problem thus far

 File "test.py", line 152
if len(args) == 1 and args[0] = "-c":



Should have been fine, unless my memory of sys.argv contents was
wrong (as I recall, sys.argv, if it behaves like other languages, would
  

You missed the actual problem:   there's a single '=' in the second part 
of the if expression.  Should be "=="


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


Re: redoing libgmail interface to "smtplib" blah?

2009-08-15 Thread John Haggerty
I did detect one problem thus far

 File "test.py", line 152
if len(args) == 1 and args[0] = "-c":


On Sat, Aug 15, 2009 at 7:23 PM, Dennis Lee Bieber wrote:

> On Sat, 15 Aug 2009 14:23:26 -0600, John Haggerty 
> declaimed the following in gmane.comp.python.general:
>
> > The following program is theoretically supposed to use a supported
> library.
> > Issues have come up where the library is not working and now another
> > interface is being requierd to be used.
> >
> > At this point I'm looking at just changing the send commands but don't
> feel
> > confident in doing so. Wondering specifically what would have to be
> changed
> > to what.
> >
> > Thanks for your time :)
>
> Ugh... I'm afraid if I attacked this program I'd have to
> restructure
> the entire thing... There are no signs of any functional decomposition
> in that -- if Python had an unstructured GOTO, I'd suspect this would
> have been a spaghetti-code program... As it is, the best I can call it
> is lasagna-code  (interwoven but distinct layers in a linear form
> from one end to the other).
>
>
> > if __name__ == "__main__":
> > import os,time,sys,libgmail
> > from subprocess import Popen,PIPE
> > main(sys.argv)
>
> Given the position of the import statements, this file can NOT be
> used as an importable module for use by other programs, so the whole
> breakdown of a main() is meaningless; might as well remove that if, the
> def main(): line, move the imports to the top, and unindent the rest one
> level.
>
>All those embedded calls to exit() also offend me; I'm from the "one
> in, one out" school (though I'll use break and continue in a loop, I
> still favor just one usage of them in such)
>
>Ideally, all the SMS related stuff would be isolated apart from the
> email stuff. Would make changing email interface a lot more intuitive.
>
>Out of a fit of boredom, though it probably doesn't help your real
> problem, and it has not been tested at all, this is my restructuring of
> the code listing.
>
> -=-=-=-=-=-=-=-
> import os
> import time
> import sys
> import subprocess
>
> import libgmail
>
>
> CARRIERLIST = [   ("3 River Wireless", "@sms.3rivers.net"),
>   ("7-11 Speakout","@cingularme.com"),
>  #("Airtel (Karnataka","India) Alaska
> Communications Systems"),
>  ("Alltel Wireless","@message.alltel.com"),
>  ("AT&T Wireless","@txt.att.net"),
>  ("Bell Mobility (Canada)","@txt.bell.ca"),
>  ("Boost Mobile","@myboostmobile.com"),
>  ("Cellular One (Dobson)","@mobile.celloneusa.com"),
>  ("Cingular (Postpaid)","@cingularme.com"),
>  ("Centennial Wireless","@cwemail.com"),
>  ("Cingular (GoPhone prepaid)","@cingularme.com"),
>  ("Claro (Nicaragua)","@ideasclaro-ca.com"),
>  ("Comcel","@comcel.com.co"),
>  ("Cricket","@sms.mycricket.com"),
>  ("CTI","@sms.ctimovil.com.ar"),
>  ("Emtel (Mauritius)","@emtelworld.net"),
>  ("Fido (Canada)","@fido.ca"),
>  ("General Communications Inc.","@msg.gci.net"),
>  ("Globalstar","@msg.globalstarusa.com"),
>  ("Helio","@myhelio.com"),
>  ("Illinois Valley Cellular","@ivctext.com"),
>  #("i wireless","@iwspcs.net"),
>  ("Meteor (Ireland)","@sms.mymeteor.ie"),
>  ("Mero Mobile (Nepal)","@sms.spicenepal.com"),
>  ("MetroPCS","@mymetropcs.com"),
>  ("Movicom","@movimensaje.com.ar"),
>  ("Mobitel (Sri Lanka)","@sms.mobitel.lk"),
>  ("Movistar (Colombia)","@movistar.com.co"),
>  ("MTN (South Africa)","@sms.co.za"),
>  ("MTS (Canada)","@text.mtsmobility.com"),
>  ("Nextel (Argentina)","@nextel.net.ar"),
>  ("Orange (Poland)","@orange.pl"),
>  ("Personal (Argentina)","@personal-net.com.ar"),
>  ("Plus GSM (Poland)","@text.plusgsm.pl"),
>  ("President's Choice (Canada)","@txt.bell.ca"),
>  ("Qwest","@qwestmp.com"),
>  ("Rogers (Canada)","@pcs.rogers.com"),
>  ("Sasktel (Canada)","@sms.sasktel.com"),
>  ("Setar Mobile email (Aruba)","@mas.aw"),
>  ("Solo Mobile","@txt.bell.ca"),
>  ("Sprint (PCS)","@messaging.sprintpcs.com"),
>  ("Sprint (Nextel)","@page.nextel.com"),
>  ("Suncom","@tms.suncom.com"),
>  ("T-Mobile","@tmomail.net"),
>  ("T-Mobile (Austria)","@sms.t-mobile.at"),
>  ("Telus Mobility (Canada)","@msg.telus.com"),
>  ("Thumb Cellular","@sms.thumbcellular.com"),
>  ("Tigo (Formerly Ola)"

Re: redoing libgmail interface to "smtplib" blah?

2009-08-15 Thread John Haggerty
On Sat, Aug 15, 2009 at 7:23 PM, Dennis Lee Bieber wrote:

> On Sat, 15 Aug 2009 14:23:26 -0600, John Haggerty 
> declaimed the following in gmane.comp.python.general:
>
> > The following program is theoretically supposed to use a supported
> library.
> > Issues have come up where the library is not working and now another
> > interface is being requierd to be used.
> >
> > At this point I'm looking at just changing the send commands but don't
> feel
> > confident in doing so. Wondering specifically what would have to be
> changed
> > to what.
> >
> > Thanks for your time :)
>
> Ugh... I'm afraid if I attacked this program I'd have to
> restructure
> the entire thing... There are no signs of any functional decomposition
> in that -- if Python had an unstructured GOTO, I'd suspect this would
> have been a spaghetti-code program... As it is, the best I can call it
> is lasagna-code  (interwoven but distinct layers in a linear form
> from one end to the other).
>
>
> > if __name__ == "__main__":
> > import os,time,sys,libgmail
> > from subprocess import Popen,PIPE
> > main(sys.argv)
>
> Given the position of the import statements, this file can NOT be
> used as an importable module for use by other programs, so the whole
> breakdown of a main() is meaningless; might as well remove that if, the
> def main(): line, move the imports to the top, and unindent the rest one
> level.
>
>All those embedded calls to exit() also offend me; I'm from the "one
> in, one out" school (though I'll use break and continue in a loop, I
> still favor just one usage of them in such)
>
>Ideally, all the SMS related stuff would be isolated apart from the
> email stuff. Would make changing email interface a lot more intuitive.
>
>Out of a fit of boredom, though it probably doesn't help your real
> problem, and it has not been tested at all, this is my restructuring of
> the code listing.
>
> -=-=-=-=-=-=-=-
> import os
> import time
> import sys
> import subprocess
>
> import libgmail
>
>
> CARRIERLIST = [   ("3 River Wireless", "@sms.3rivers.net"),
>   ("7-11 Speakout","@cingularme.com"),
>  #("Airtel (Karnataka","India) Alaska
> Communications Systems"),
>  ("Alltel Wireless","@message.alltel.com"),
>  ("AT&T Wireless","@txt.att.net"),
>  ("Bell Mobility (Canada)","@txt.bell.ca"),
>  ("Boost Mobile","@myboostmobile.com"),
>  ("Cellular One (Dobson)","@mobile.celloneusa.com"),
>  ("Cingular (Postpaid)","@cingularme.com"),
>  ("Centennial Wireless","@cwemail.com"),
>  ("Cingular (GoPhone prepaid)","@cingularme.com"),
>  ("Claro (Nicaragua)","@ideasclaro-ca.com"),
>  ("Comcel","@comcel.com.co"),
>  ("Cricket","@sms.mycricket.com"),
>  ("CTI","@sms.ctimovil.com.ar"),
>  ("Emtel (Mauritius)","@emtelworld.net"),
>  ("Fido (Canada)","@fido.ca"),
>  ("General Communications Inc.","@msg.gci.net"),
>  ("Globalstar","@msg.globalstarusa.com"),
>  ("Helio","@myhelio.com"),
>  ("Illinois Valley Cellular","@ivctext.com"),
>  #("i wireless","@iwspcs.net"),
>  ("Meteor (Ireland)","@sms.mymeteor.ie"),
>  ("Mero Mobile (Nepal)","@sms.spicenepal.com"),
>  ("MetroPCS","@mymetropcs.com"),
>  ("Movicom","@movimensaje.com.ar"),
>  ("Mobitel (Sri Lanka)","@sms.mobitel.lk"),
>  ("Movistar (Colombia)","@movistar.com.co"),
>  ("MTN (South Africa)","@sms.co.za"),
>  ("MTS (Canada)","@text.mtsmobility.com"),
>  ("Nextel (Argentina)","@nextel.net.ar"),
>  ("Orange (Poland)","@orange.pl"),
>  ("Personal (Argentina)","@personal-net.com.ar"),
>  ("Plus GSM (Poland)","@text.plusgsm.pl"),
>  ("President's Choice (Canada)","@txt.bell.ca"),
>  ("Qwest","@qwestmp.com"),
>  ("Rogers (Canada)","@pcs.rogers.com"),
>  ("Sasktel (Canada)","@sms.sasktel.com"),
>  ("Setar Mobile email (Aruba)","@mas.aw"),
>  ("Solo Mobile","@txt.bell.ca"),
>  ("Sprint (PCS)","@messaging.sprintpcs.com"),
>  ("Sprint (Nextel)","@page.nextel.com"),
>  ("Suncom","@tms.suncom.com"),
>  ("T-Mobile","@tmomail.net"),
>  ("T-Mobile (Austria)","@sms.t-mobile.at"),
>  ("Telus Mobility (Canada)","@msg.telus.com"),
>  ("Thumb Cellular","@sms.thumbcellular.com"),
>  ("Tigo (Formerly Ola)","@sms.tigo.com.co"),
>  ("Unicel","@utext.com"),
>  ("US Cellular","@ema

redoing libgmail interface to "smtplib" blah?

2009-08-15 Thread John Haggerty
The following program is theoretically supposed to use a supported library.
Issues have come up where the library is not working and now another
interface is being requierd to be used.

At this point I'm looking at just changing the send commands but don't feel
confident in doing so. Wondering specifically what would have to be changed
to what.

Thanks for your time :)

#!/usr/bin/env python
#
# ogss -- SMS Shell through Gmail and libgmail
#
# Version 0.2
#
# Author: bto...@mastahyeti.com
#
# License: GPL 2.0
#
# NOTE:
#   You should ensure you are permitted to use this script before using it
#   to access Google's Gmail servers.
#
def main(argv):
print "Starting ogss"

logfile = os.path.join(os.environ["HOME"],"ogss.log")
print "Logfile at:"+logfile
execd = []
#Checking to see if the logfile already exists
#if it doesn't we create it.
if not os.path.exists(logfile):
print "Creating log file"
try:
open(logfile,"w").close()
except:
print "Failed to open create log file. Check permissions"
exit()
#Opening log file for reading and parseing its contents into a list
#Must do this to ensure that we dont execute old commands
print "Opening log file for reading"
try:
r = open(logfile,"r")
for line in r:
eid = line.split("~")
if len(eid)>=2:
execd.append(int(eid[0]))
r.close()
except:
print "Failed to open or read log file. Check permissions"
exit()

clist = [["3 River Wireless","@sms.3rivers.net"],["7-11 Speakout","@
cingularme.com"],["Airtel (Karnataka","India)Alaska Communications
Systems"],["Alltel Wireless","@message.alltel.com"],["AT&T Wireless","@
txt.att.net"],["Bell Mobility (Canada)","@txt.bell.ca"],["Boost Mobile","@
myboostmobile.com"],["Cellular One
(Dobson)","@mobile.celloneusa.com"],["Cingular
(Postpaid)","@cingularme.com"],["Centennial
Wireless","@cwemail.com"],["Cingular
(GoPhone prepaid)","@cingularme.com"],["Claro (Nicaragua)","@
ideasclaro-ca.com"],["Comcel","@comcel.com.co"],["Cricket","@
sms.mycricket.com"],["CTI","@sms.ctimovil.com.ar"],["Emtel (Mauritius)","@
emtelworld.net"],["Fido (Canada)","@fido.ca"],["General Communications
Inc.","@msg.gci.net"],["Globalstar","@msg.globalstarusa.com"],["Helio","@
myhelio.com"],["Illinois Valley Cellular","@ivctext.com"],["i wireless",".
i...@iwspcs.net"],["Meteor (Ireland)","@sms.mymeteor.ie"],["Mero Mobile
(Nepal)","@sms.spicenepal.com"],["MetroPCS","@mymetropcs.com"],["Movicom","@
movimensaje.com.ar"],["Mobitel (Sri Lanka)","@sms.mobitel.lk"],["Movistar
(Colombia)","@movistar.com.co"],["MTN (South Africa)","@sms.co.za"],["MTS
(Canada)","@text.mtsmobility.com"],["Nextel
(Argentina)","@nextel.net.ar"],["Orange
(Poland)","@orange.pl"],["Personal (Argentina)","@personal-net.com.ar"],["Plus
GSM (Poland)","@text.plusgsm.pl"],["President\s Choice (Canada)","@
txt.bell.ca"],["Qwest","@qwestmp.com"],["Rogers
(Canada)","@pcs.rogers.com"],["Sasktel
(Canada)","@sms.sasktel.com"],["Setar Mobile email (Aruba)","@mas.aw"],["Solo
Mobile","@txt.bell.ca"],["Sprint (PCS)","@messaging.sprintpcs.com"],["Sprint
(Nextel)","@page.nextel.com"],["Suncom","@tms.suncom.com"],["T-Mobile","@
tmomail.net"],["T-Mobile (Austria)","@sms.t-mobile.at"],["Telus Mobility
(Canada)","@msg.telus.com"],["Thumb Cellular","@sms.thumbcellular.com"],["Tigo
(Formerly Ola)","@sms.tigo.com.co"],["Unicel","@utext.com"],["US
Cellular","@email.uscc.net"],["Verizon","@vtext.com"],["Virgin Mobile
(Canada)","@vmobile.ca"],["Virgin Mobile (USA)","@vmobl.com"],["YCC","@
sms.ycc.ru"],["Orange (UK)","@orange.net"],["Cincinnati Bell Wireless","@
gocbw.com"],["T-Mobile Germany","@t-mobile-sms.de"],["Vodafone Germany","@
vodafone-sms.de"],["E-Plus","@smsmail.eplus.de"]]

print "Parsing user input"
if len(argv)<4:
if len(argv) == 2:
if argv[1] == "-c":
counter = 0
for car in clist:
print str(counter) + "--" + car[0]
counter += 1
exit()
else:
print
"--Useage---\n\r--Start
Service --- ogss.py USERNAME PASSWORD CELL-NUMBER
CARRIER-NUMBER\n\r--List carriers --- ogss.py -c"
print "--Useage from
phone\n\r--Ogss
COMMAND"
exit()
username   = argv[1]
password   = argv[2]
number = argv[3]
carrier = clist[int(argv[4])]
cell_email = number+carrier[1]

print "Connecting to Gmail"
account = libgmail.GmailAccount(username,password)
print "Logging into Gmail"
account.login()

print "Opening log file for writing"
try:
w = open(logfile,"a")
except:
print "Failed to open log file. Check permissions."
exit()

#If the logfile is empty (if this is the first use) we want to

SMTPlib and SMTPd Performance Issues

2009-07-21 Thread Casey McGinty
Hi,

I just wanted mention a few workarounds I've come up with for the Python
SMTP modules in regards to performance.

Before I started, I was getting about 15MB/s while sending e-mail from
smtplib to smptd over a local connection. (i.e. both client/server running
on the same machine). After the following changes, I'm seeing around*220+MB/s
* (increase of 14x)

The source can be found here:
http://svn.python.org/view/python/trunk/Lib/smtplib.py?view=markup
http://svn.python.org/view/python/trunk/Lib/smtpd.py?view=markup

When sending e-mail through *smtpdlib*, the following method is called.

def quotedata(data):
"""Quote data for email.

Double leading '.', and change Unix newline '\\n', or Mac '\\r' into
Internet CRLF end-of-line.
"""
return re.sub(r'(?m)^\.', '..',
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))


As you can see there are two regular expressions parsing the data. If you
know that your message is formatted correctly to start with, then this step
is unnecessary.

When receiving e-mail through *smtpd*, the SMTPChannel class inherits from *
asynchat.async_chat*. The default recv buffer size for asynchat is 4K. This
can be too much overhead for high data throughput. The buffer size can be
increased with this code:

import asynchat
asynchat.async_chat.ac_in_buffer_size  = 1024*128
asynchat.async_chat.ac_out_buffer_size = 1024*128

The *smtpd.SMTP* class prcoesses data through the *smtpd.SMTPChannel* class.
There are a lot of debug statements in the module, like so:

print >> DEBUGSTREAM, 'Data:', repr(line)

By default, DEBUGSTREAM is a no-op, but that that doesn't prevent
repr(line) from being called. When variable, line, contains a large
email (multiple megabytes),
this debug step will really kill performance.

Secondly, the method *found_terminator* will also perform expensive
strings ops on the e-mail. Maybe its not possible to disable this
step, in all cases,
but for testing performance, you can override the method like so:

class QuickSMTPChannel( smtpd.SMTPChannel, object):
   def found_terminator(self):
  if (self._SMTPChannel__state == self.COMMAND or
self._SMTPChannel__state != self.DATA):
 super(QuickSMTPChannel,self).found_terminator()
  else:
 data = smtpd.EMPTYSTRING.join(self._SMTPChannel__line)
 self._SMTPChannel__line = []
 status = self._SMTPChannel__server.process_message(
   self._SMTPChannel__peer, self._SMTPChannel__mailfrom,
   self._SMTPChannel__rcpttos, data)
 self._SMTPChannel__rcpttos = []
 self._SMTPChannel__mailfrom = None
 self._SMTPChannel__state = self.COMMAND
 self.set_terminator('\r\n')
 if not status:
 self.push('250 Ok')
 else:
 self.push(status

Thanks,

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


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Alex Jurkiewicz

Piet van Oostrum wrote:

AJ> if __name__ == '__main__':
AJ>THREADS = []
AJ>for i in range(CONCURRENCY):
AJ>THREADS.append(threading.Thread(target=threadProcessRecipient))
AJ>for thread in THREADS:
AJ>thread.run()



You should use thread.start(), not thread.run(). When you use run(), it
will be sequential execution, as you experience. With start() you get
concurrency
  


Thanks! Changing this method call fixes the original problem we saw. In 
the process I've run into another though, seemingly a race condition / 
deadlock.


Our email script DKIM signs all messages with pydkim. Because this is so 
CPU intensive we run the signing in an external process, using 
dkimsign.py (which basically accepts the message on stdin, calls 
dkim.sign() on it and passes the result back on stdout). We call the 
DKIM signing while preparing each message in each thread like this:

cmd = subprocess.Popen(
   ['/usr/bin/nice', PYTHONBIN, 'dkimsign.py',
   DKIMSELECTOR,
   DKIMDOMAIN,
   DKIMPRIVATEKEYFILE],
   stdin = subprocess.PIPE,
   stdout = subprocess.PIPE)
message = cmd.communicate(message)[0]

The majority of the time (80%) our mail merge works fine -- messages are 
sent out in a multi-threaded manner. The rest of the time, some of the 
threads deadlock when calling dkimsign.py. Specifically, they stop 
during the communicate() call above. dkimsign.py never receives any 
input (hangs on message=sys.stdin.read()), and sits there waiting 
forever, which stops the thread from doing anything.


Is this a bug with subprocess? Is there some way to set a timeout on the 
communicate() call so I can detect these locks?


Cheers,
AJ
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Piet van Oostrum
> Alex Jurkiewicz  (AJ) wrote:

>AJ> def threadProcessRecipient():
[snip]
>AJ> if __name__ == '__main__':
>AJ>THREADS = []
>AJ>for i in range(CONCURRENCY):
>AJ>THREADS.append(threading.Thread(target=threadProcessRecipient))
>AJ>for thread in THREADS:
>AJ>thread.run()

You should use thread.start(), not thread.run(). When you use run(), it
will be sequential execution, as you experience. With start() you get
concurrency
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: [SPAM] Re: Threaded alternatives to smtplib?

2009-05-04 Thread MRAB

Diez B. Roggisch wrote:

Alex Jurkiewicz schrieb:

Hi all,
I'm writing a Python script to do a "mail merge" style email 
distribution. I create a few python threads and in each one I call 
`smtpserver = smtplib.SMTP(our.smtpserver.com)`. However, during the 
sending process, there seems to be only one connection open to our 
mail server at any one time. In other words, all these threads gain me 
no speed benefit at all!


I seem to be running into the issue where smtplib is not fully 
thread-safe, as mentioned in this thread:

http://mail.python.org/pipermail/python-list/2007-March/429067.html
http://mail.python.org/pipermail/python-list/2007-March/429172.html

Does anyone have suggestions as to a suitable workaround for this 
issue? I was looking at the Twisted library, which seems possible but 
significantly more complex.


I doubt that there is such issue. The above discussion is not concluding 
that there actually *are* threading-issues within smtplib. And looking 
at the source of smtplib, it certainly doesn't use any 
locking-primitives or (directly) any c-extension that might explain such 
behavior.


Without more code, it's impossible to tell if there is anything peculiar 
in your usage of the lib. Maybe you close your connections to fast to 
see several open?



If all the threads are using the same server, couldn't the SMTP part be
put into its own thread and then fed the pre-composed emails via a
queue?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Diez B. Roggisch
Diez B. Roggisch wrote:

> Alex Jurkiewicz wrote:
> 
>> Gabriel Genellina wrote:
>>> Try logging the start/stop of your threads. It may be that your
>>> threads stop before you think. The above code works correctly only if
>>> you fill the queue before starting any thread - because as soon as a
>>> thread sees the queue empty, it finishes.
>>> You could use the sample code in the Queue documentation at the end of
>>> http://docs.python.org/library/queue.htm
>> The queue is actually filled before the threads are started, data is
>> only removed after they start.
>> 
>> Logging thread state (at least in debug mode) would be good though. How
>> would I go about it in this example? The docs suggest using thread.name,
>> but in my current setup I don't have any idea which thread is running.
>> Something like this:
>> for i in range(CONCURRENCY):
>> THREADS.append( threading.Thread(target=threadProcessRecipient,
>> args=i, name=i) )
>> 
>> And:
>> 
>> def threadProcessRecipient(name):
>> print "Name is %s" % name
> 

Oh, and I forgot - threading.currentThread() gets you the actively running
thread of course.

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


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Diez B. Roggisch
Alex Jurkiewicz wrote:

> Gabriel Genellina wrote:
>> Try logging the start/stop of your threads. It may be that your
>> threads stop before you think. The above code works correctly only if
>> you fill the queue before starting any thread - because as soon as a
>> thread sees the queue empty, it finishes.
>> You could use the sample code in the Queue documentation at the end of
>> http://docs.python.org/library/queue.htm
> The queue is actually filled before the threads are started, data is
> only removed after they start.
> 
> Logging thread state (at least in debug mode) would be good though. How
> would I go about it in this example? The docs suggest using thread.name,
> but in my current setup I don't have any idea which thread is running.
> Something like this:
> for i in range(CONCURRENCY):
> THREADS.append( threading.Thread(target=threadProcessRecipient,
> args=i, name=i) )
> 
> And:
> 
> def threadProcessRecipient(name):
> print "Name is %s" % name

Each thread gets an unique name assigned anyway. Alternatively, you can use
partial to bind parameters to functions. And last but not least to subclass
Thread is also an option.

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


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Alex Jurkiewicz

Gabriel Genellina wrote:
Try logging the start/stop of your threads. It may be that your 
threads stop before you think. The above code works correctly only if 
you fill the queue before starting any thread - because as soon as a 
thread sees the queue empty, it finishes.
You could use the sample code in the Queue documentation at the end of 
http://docs.python.org/library/queue.htm
The queue is actually filled before the threads are started, data is 
only removed after they start.


Logging thread state (at least in debug mode) would be good though. How 
would I go about it in this example? The docs suggest using thread.name, 
but in my current setup I don't have any idea which thread is running. 
Something like this:

for i in range(CONCURRENCY):
   THREADS.append( threading.Thread(target=threadProcessRecipient, 
args=i, name=i) )


And:

def threadProcessRecipient(name):
   print "Name is %s" % name


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


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Gabriel Genellina
En Mon, 04 May 2009 04:19:21 -0300, Alex Jurkiewicz  
 escribió:

Diez B. Roggisch wrote:
Without more code, it's impossible to tell if there is anything  
peculiar in your usage of the lib. Maybe you close your connections to  
fast to see several open?


Here's the relevant stuff from my (python2.6) code:


CONCURRENCY = 3

def threadProcessRecipient():
# Each thread has its own SMTP connection
smtpserver = smtplib.SMTP(SMTPSERVER)
   # Each thread pulls a recipient entry from the queue to process  
and loops until the queue is empty.

try:
recipientData = recipientQueue.get_nowait()
except Queue.Empty:
recipientData = None
   while recipientData:
message = prepareMessage()
sendMail(senderEmail, recipientEmail, message, smtpserver)
   recipientQueue.task_done()
try:
recipientData = recipientQueue.get_nowait()
except Queue.Empty:
recipientData = None
   smtpserver.quit()


Try logging the start/stop of your threads. It may be that your threads  
stop before you think. The above code works correctly only if you fill the  
queue before starting any thread - because as soon as a thread sees the  
queue empty, it finishes.
You could use the sample code in the Queue documentation at the end of  
http://docs.python.org/library/queue.html


--
Gabriel Genellina

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


Re: Threaded alternatives to smtplib?

2009-05-04 Thread Alex Jurkiewicz

Diez B. Roggisch wrote:
Without more code, it's impossible to tell if there is anything 
peculiar in your usage of the lib. Maybe you close your connections to 
fast to see several open?


Here's the relevant stuff from my (python2.6) code:


CONCURRENCY = 3

def threadProcessRecipient():
   # Each thread has its own SMTP connection
   smtpserver = smtplib.SMTP(SMTPSERVER)
  
   # Each thread pulls a recipient entry from the queue to process and 
loops until the queue is empty.

   try:
   recipientData = recipientQueue.get_nowait()
   except Queue.Empty:
   recipientData = None
  
   while recipientData:

   message = prepareMessage()
   sendMail(senderEmail, recipientEmail, message, smtpserver)
  
   recipientQueue.task_done()

   try:
   recipientData = recipientQueue.get_nowait()
   except Queue.Empty:
   recipientData = None
  
   smtpserver.quit()


if __name__ == '__main__':
   THREADS = []
   for i in range(CONCURRENCY):
   THREADS.append(threading.Thread(target=threadProcessRecipient))
   for thread in THREADS:
   thread.run()
   for thread in THREADS:
   thread.join()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded alternatives to smtplib?

2009-05-03 Thread Diez B. Roggisch

Alex Jurkiewicz schrieb:

Hi all,
I'm writing a Python script to do a "mail merge" style email 
distribution. I create a few python threads and in each one I call 
`smtpserver = smtplib.SMTP(our.smtpserver.com)`. However, during the 
sending process, there seems to be only one connection open to our mail 
server at any one time. In other words, all these threads gain me no 
speed benefit at all!


I seem to be running into the issue where smtplib is not fully 
thread-safe, as mentioned in this thread:

http://mail.python.org/pipermail/python-list/2007-March/429067.html
http://mail.python.org/pipermail/python-list/2007-March/429172.html

Does anyone have suggestions as to a suitable workaround for this issue? 
I was looking at the Twisted library, which seems possible but 
significantly more complex.


I doubt that there is such issue. The above discussion is not concluding 
that there actually *are* threading-issues within smtplib. And looking 
at the source of smtplib, it certainly doesn't use any 
locking-primitives or (directly) any c-extension that might explain such 
behavior.


Without more code, it's impossible to tell if there is anything peculiar 
in your usage of the lib. Maybe you close your connections to fast to 
see several open?


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


Threaded alternatives to smtplib?

2009-05-03 Thread Alex Jurkiewicz

Hi all,
I'm writing a Python script to do a "mail merge" style email 
distribution. I create a few python threads and in each one I call 
`smtpserver = smtplib.SMTP(our.smtpserver.com)`. However, during the 
sending process, there seems to be only one connection open to our mail 
server at any one time. In other words, all these threads gain me no 
speed benefit at all!


I seem to be running into the issue where smtplib is not fully 
thread-safe, as mentioned in this thread:

http://mail.python.org/pipermail/python-list/2007-March/429067.html
http://mail.python.org/pipermail/python-list/2007-March/429172.html

Does anyone have suggestions as to a suitable workaround for this issue? 
I was looking at the Twisted library, which seems possible but 
significantly more complex.



Thanks,
Alex Jurkiewicz
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib send email by using gmail smtp server

2009-05-03 Thread tiefeng wu
>
> I've tested with 3.0.1 on Windows XP and worked fine. Seems to be a problem
> in the SSL support, but that's all I could say.
>
> --
> Gabriel Genellina
>

thanks, I'll check SSL support on my system

Tiefeng Wu
2009-05-04
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib send email by using gmail smtp server

2009-05-03 Thread Gabriel Genellina
En Sun, 03 May 2009 12:18:33 -0300, tiefeng wu   
escribió:



I'm tring send email using smtp.gmail.com

here's the code:

*s = SMTP('**smtp.gmail.com* *', 25)
s.set_debuglevel(1)*
*s.ehlo()
s.starttls()
s.ehlo()
s.login(mygmailaccount, mygmailpassword)
s.sendmail(from_addr, to_addr_list, message)
s.close()*


I've tested with 3.0.1 on Windows XP and worked fine. Seems to be a  
problem in the SSL support, but that's all I could say.


--
Gabriel Genellina

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


smtplib send email by using gmail smtp server

2009-05-03 Thread tiefeng wu
Hi all

I'm tring send email using smtp.gmail.com

here's the code:

*s = SMTP('**smtp.gmail.com* *', 25)
s.set_debuglevel(1)*
*s.ehlo()
s.starttls()
s.ehlo()
s.login(mygmailaccount, mygmailpassword)
s.sendmail(from_addr, to_addr_list, message)
s.close()*

I got the following:

*send: 'ehlo [192.168.1.104]\r\n'
reply: b'**250-mx.google.com* * at your service,
[58.39.112.163]\r\n'
reply: b'250-SIZE 35651584\r\n'
reply: b'250-8BITMIME\r\n'
reply: b'250-STARTTLS\r\n'
reply: b'250-ENHANCEDSTATUSCODES\r\n'
reply: b'250 PIPELINING\r\n'
reply: retcode (250); Msg: b'**mx.google.com* * at
your service, [58.39.112.163]\nSIZE 35651584\n8BITMIME\nSTARTTLS\nENHANCED
STATUSCODES\nPIPELINING'
send: 'STARTTLS\r\n'
reply: b'220 2.0.0 Ready to start TLS\r\n'
reply: retcode (220); Msg: b'2.0.0 Ready to start TLS'*

After a long time waiting I got:

*Traceback (most recent call last):
...
  File "sendmail.py", line 56, in send_mail
s.starttls()
  File "C:\usr\bin\python30\lib\smtplib.py", line 619, in starttls
self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)
  File "C:\usr\bin\python30\lib\ssl.py", line 381, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
  File "C:\usr\bin\python30\lib\ssl.py", line 135, in __init__
raise x
  File "C:\usr\bin\python30\lib\ssl.py", line 131, in __init__
self.do_handshake()
  File "C:\usr\bin\python30\lib\ssl.py", line 327, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [Errno 8] _ssl.c:486: EOF occurred in violation of protocol*

After this I tried port 465, I got no debug messages like "send...
reply...", and after a long time waiting the following exception occured:

*Traceback (most recent call last):
...*
*  File "sendmail.py", line 49, in send_mail
s = SMTP('smtp.gmail.com', 465)
  File "C:\usr\bin\python30\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
  File "C:\usr\bin\python30\lib\smtplib.py", line 296, in connect
(code, msg) = self.getreply()
  File "C:\usr\bin\python30\lib\smtplib.py", line 342, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed*

Am I doing something wrong? I'm using python30 and python31a2 under Windows
XP

thanks!

Tiefeng Wu
2009-05-03
--
http://mail.python.org/mailman/listinfo/python-list


imaplib and smtplib

2009-04-19 Thread Vistro
I want to download a message from my Gmail inbox with imaplib, then forward
(basically resend it) with smtplib. I can log in with both. I just need to
know how to download a message with imaplib, and what needs to be converted
into what to be able to send it with smtplib.

For a good time, go to Start:Run and type in format C<http://www.vistro.net/>
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib problem with newly rebuilt Debian/lenny system

2009-03-30 Thread cassiope
On Mar 27, 11:29 am, a...@pythoncraft.com (Aahz) wrote:
> [posted & e-mailed, please respond to newsgroup]
>
> In article ,
>
>
>
> cassiope   wrote:
>
> >In attempting to diagnose the cause, I tried directly executing the
> >lines inside the python2.5 interpreter:
>
> >        import  smtplib
> >        s= smtplib.SMTP('localhost')
>
> >but the second line causes  a traceback:
>
> >        File "", line 1, in 
> >        File "/usr/lib/python2.5/smtplib.py", line 244, in __init__
> >            (code, msg) = self.connect(host, port)
> >        File "/usr/lib/python2.5/smtplib.py", line 310, in connect
> >            raise socket.error, msg
> >        socket.error: (97, 'Address family not supported by protocol')
>
> >This is with exim4 and python2.5 on a newly installed lenny system.
> >No error messages appear in /var/log or /var/log/exim4 directories.
>
> What happens if you
> telnet localhost 25
>
> This looks like a network setup issue.
> --
> Aahz (a...@pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> "At Resolver we've found it useful to short-circuit any doubt and just
> refer to comments in code as 'lies'. :-)"
> --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-3-22

Yes, that's what it was.  Exim4 setup was bungled, so wasn't accepting
localhost
connections.  Fixing that resolved the "python" error.
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib problem with newly rebuilt Debian/lenny system

2009-03-30 Thread BJ Swope
try
 s=smtplib.SMTP('127.0.0.1')

instead.  I'm guessing that it's trying to bind to the IPv6 or some other
non IPv4 localhost instance.

On Wed, Mar 18, 2009 at 11:25 AM, cassiope  wrote:

> A hard drive failure forced me to rebuild my main system.  Just a few
> things haven't been restored; one of them is a python script which is
> used to email users of important events.
>
> In attempting to diagnose the cause, I tried directly executing the
> lines inside the python2.5 interpreter:
>
>import  smtplib
>s= smtplib.SMTP('localhost')
>
> but the second line causes  a traceback:
>
>File "", line 1, in 
>File "/usr/lib/python2.5/smtplib.py", line 244, in __init__
>(code, msg) = self.connect(host, port)
>File "/usr/lib/python2.5/smtplib.py", line 310, in connect
>raise socket.error, msg
>socket.error: (97, 'Address family not supported by protocol')
>
> This is with exim4 and python2.5 on a newly installed lenny system.
> No error messages appear in /var/log or /var/log/exim4 directories.
>
> Helpful clues or pointers to relevant documentation would be
> appreciated!
>
>-f
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay

Fascism is a term used to describe authoritarian nationalist political
ideologies or mass movements that are concerned with notions of cultural
decline or decadence and seek to achieve a millenarian national rebirth by
exalting the nation or race, and promoting cults of unity, strength and
purity. - Wikipedia

The story of postwar American conservatism is best understood as a continual
replay of a single long-standing debate. On one side are those who have
upheld the Burkean ideal of replenishing civil society by adjusting to
changing conditions. On the other are those committed to a revanchist
counterrevolution, the restoration of America's pre-welfare state ancien
regime. And, time and again, the counterrevolutionaries have won. The result
is that modern American conservatism has dedicated itself not to fortifying
and replenishing civil society but rather to weakening it through a politics
of civil warfare. -- Sam Tanenhaus
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib problem with newly rebuilt Debian/lenny system

2009-03-27 Thread Aahz
[posted & e-mailed, please respond to newsgroup]

In article ,
cassiope   wrote:
>
>In attempting to diagnose the cause, I tried directly executing the
>lines inside the python2.5 interpreter:
>
>import  smtplib
>s= smtplib.SMTP('localhost')
>
>but the second line causes  a traceback:
>
>File "", line 1, in 
>File "/usr/lib/python2.5/smtplib.py", line 244, in __init__
>(code, msg) = self.connect(host, port)
>File "/usr/lib/python2.5/smtplib.py", line 310, in connect
>raise socket.error, msg
>socket.error: (97, 'Address family not supported by protocol')
>
>This is with exim4 and python2.5 on a newly installed lenny system.
>No error messages appear in /var/log or /var/log/exim4 directories.

What happens if you 
telnet localhost 25

This looks like a network setup issue.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)"
--Michael Foord paraphrases Christian Muirhead on python-dev, 2009-3-22
--
http://mail.python.org/mailman/listinfo/python-list


smtplib problem with newly rebuilt Debian/lenny system

2009-03-18 Thread cassiope
A hard drive failure forced me to rebuild my main system.  Just a few
things haven't been restored; one of them is a python script which is
used to email users of important events.

In attempting to diagnose the cause, I tried directly executing the
lines inside the python2.5 interpreter:

import  smtplib
s= smtplib.SMTP('localhost')

but the second line causes  a traceback:

File "", line 1, in 
File "/usr/lib/python2.5/smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.5/smtplib.py", line 310, in connect
raise socket.error, msg
socket.error: (97, 'Address family not supported by protocol')

This is with exim4 and python2.5 on a newly installed lenny system.
No error messages appear in /var/log or /var/log/exim4 directories.

Helpful clues or pointers to relevant documentation would be
appreciated!

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


sending gmail with smtplib from behind a proxy

2009-02-26 Thread Bjorn
Hi, I tried the script below to send mail by gmail from python using
smptlib. I got the script here (http://kutuma.blogspot.com/2007/08/
sending-emails-via-gmail-with-python.html)

It works fine from home, but at work not. I think it is because I am
behind a http or a socks proxy server at work. Can I adapt this script
to work from behind the http or socks proxy? I couldnt understand from
the smtplib if I can specify this somehow?

Sincerely,
bjorn johansson

Script-
#!/usr/bin/python

import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os

gmail_user = "your_em...@gmail.com"
gmail_pwd = "your_password"

def mail(to, subject, text, attach):
   msg = MIMEMultipart()

   msg['From'] = gmail_user
   msg['To'] = to
   msg['Subject'] = subject

   msg.attach(MIMEText(text))

   part = MIMEBase('application', 'octet-stream')
   part.set_payload(open(attach, 'rb').read())
   Encoders.encode_base64(part)
   part.add_header('Content-Disposition',
   'attachment; filename="%s"' % os.path.basename(attach))
   msg.attach(part)

   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(gmail_user, gmail_pwd)
   mailServer.sendmail(gmail_user, to, msg.as_string())
   # Should be mailServer.quit(), but that crashes...
   mailServer.close()

mail("some.per...@some.address.com",
   "Hello from python!",
   "This is a email sent with python",
   "my_picture.jpg")
--
http://mail.python.org/mailman/listinfo/python-list


Re: email varification using smtplib or any method

2009-02-20 Thread Gabriel Genellina
En Fri, 20 Feb 2009 02:58:24 -0200, jitendra gupta   
escribió:



when i am changing
msg['To'] = "wrongu...@wrongdomain.comddsdjsdsdsjdh"
some wrong email then i am getting back failure notice in my inbox,  
which i

dont want..
is there any way so that i can identify wrong email during the run time
(when i am sending  the email)


In practice, no, due to spam.
If you connect directly to the destination SMTP (instead of your own), you  
could try the VRFY command (if supported by the server); but most servers  
just return a generic 252 response.


--
Gabriel Genellina

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


email varification using smtplib or any method

2009-02-20 Thread jitendra gupta
hello
here is my code for sending the mail, using this code email is going
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''CODE
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import smtplib
from time import strftime
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.Utils import COMMASPACE, formatdate


# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = " is sending the mail"
msg['From'] = 'jitu.ic...@myprivatedomain.com '
msg['Date'] = formatdate(localtime=True)
msg['To'] = 'jitu.ic...@gmail.com'

# Create the body of the message (a plain-text and an HTML version).
#text = "jitendra kya huy a!\nHow are you?\nHere is the link you
wanted:\nhttp://www.python.org";
html = """\

  
  
Hi!
   How are you?
   This mail is send by wjitenrda
   Here is the http://www.python.org";>link you wanted.

  

"""

part2 = MIMEText(html, 'html')


msg.attach(part2)

# Send the message via local SMTP server.
s = smtplib.SMTP('smtp.myprivatedomain.com <http://name.com>')
s.login("user","password")
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''CODE  END
 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
using this code i am able to send the email , but problem is
when i am changing
msg['To'] = "wrongu...@wrongdomain.comddsdjsdsdsjdh"
some wrong email then i am getting back failure notice in my inbox, which i
dont want..
is there any way so that i can identify wrong email during the run time
(when i am sending  the email)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't load smtplib

2009-02-12 Thread S-boy
Thanks. Turns out I had a script I wrote called email.py in my Python
path that was screwing things up.

On Feb 12, 2:50 pm, Jean-Paul Calderone  wrote:
> On Thu, 12 Feb 2009 11:40:57 -0800 (PST), S-boy  wrote:
> >I can't seem to import smtplib in either a script or the command line
> >interpreter.
>
> >When I try to import smtp, there seems to be some kind of collision
> >with urllib2. I get a weird error about Web server authorization, even
> >though I'm not calling urllib2.
>
> >Any ideas on what might be causing this?
>
> >Here's the mess
>
> >Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
> >[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
>
> >>>> import smtplib
>
> >Traceback (most recent call last):
> >  File "", line 1, in 
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/smtplib.py", line 46, in 
> >import email.Utils
> >  File "email.py", line 4, in 
>
> Ooops.  Here's your problem.  Notice how that's not 
> /Library/Frameworks/Python.framework/Versions/2.5/lib/>python2.5/email/?  You 
> have an "email" module that's obscuring the stdlib
>
> email package.
>
>
>
> >response = urlopen("https://webmail.canwest.com";)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 124, in urlopen
> >return _opener.open(url, data)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 387, in open
> >response = meth(req, response)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 498, in http_response
> >'http', request, response, code, msg, hdrs)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 425, in error
> >return self._call_chain(*args)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 360, in _call_chain
> >result = func(*args)
> >  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> >python2.5/urllib2.py", line 506, in http_error_default
> >raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> >urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires
> >authorization to fulfill the request. Access to the Web server is
> >denied. Contact the server administrator.  )
>
> Jean-Paul

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


Re: Can't load smtplib

2009-02-12 Thread Jean-Paul Calderone

On Thu, 12 Feb 2009 11:40:57 -0800 (PST), S-boy  wrote:

I can't seem to import smtplib in either a script or the command line
interpreter.

When I try to import smtp, there seems to be some kind of collision
with urllib2. I get a weird error about Web server authorization, even
though I'm not calling urllib2.

Any ideas on what might be causing this?

Here's the mess

Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin


import smtplib


Traceback (most recent call last):
 File "", line 1, in 
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 46, in 
   import email.Utils
 File "email.py", line 4, in 


Ooops.  Here's your problem.  Notice how that's not 
/Library/Frameworks/Python.framework/Versions/2.5/lib/

python2.5/email/?  You have an "email" module that's obscuring the stdlib

email package.


   response = urlopen("https://webmail.canwest.com";)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 124, in urlopen
   return _opener.open(url, data)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 387, in open
   response = meth(req, response)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 498, in http_response
   'http', request, response, code, msg, hdrs)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 425, in error
   return self._call_chain(*args)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 360, in _call_chain
   result = func(*args)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 506, in http_error_default
   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires
authorization to fulfill the request. Access to the Web server is
denied. Contact the server administrator.  )


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


Can't load smtplib

2009-02-12 Thread S-boy
I can't seem to import smtplib in either a script or the command line
interpreter.

When I try to import smtp, there seems to be some kind of collision
with urllib2. I get a weird error about Web server authorization, even
though I'm not calling urllib2.

Any ideas on what might be causing this?

Here's the mess

Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin

>>> import smtplib

Traceback (most recent call last):
  File "", line 1, in 
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 46, in 
import email.Utils
  File "email.py", line 4, in 
response = urlopen("https://webmail.canwest.com";)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 387, in open
response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires
authorization to fulfill the request. Access to the Web server is
denied. Contact the server administrator.  )
--
http://mail.python.org/mailman/listinfo/python-list


Re: SMTPlib inside function, extra tab

2008-10-08 Thread Hunter
Thank you Tino.  I appreciate the help.

Duh!  Anything inside """ """ is preformatted text.  I have tabs
inside my preformatted text (without even thinking because it looks
more normal because of the indent).  I removed them and voila!

def send_mail(fromaddress,tolist,msgsubj,messagebody):
import smtplib
SERVER = "mymailserver.mydomain.com"
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (fromaddress, ", ".join(tolist),msgsubj, messagebody)
print message
server = smtplib.SMTP(SERVER)
server.set_debuglevel(1)
server.sendmail(fromaddress, tolist, message)
server.quit()

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


Re: SMTPlib inside function, extra tab

2008-10-07 Thread Tino Wildenhain

Hunter wrote:

I am writing a script that needs to send some emails.  And I've used
smtplib in the past and it is pretty easy.  But I thought, gee it
would be easier if I could just call it as a function, passing the
from, to, subject, and message text.  So I wrote it up as a function
and it sort of works, but I get a weird error.  When it runs it
inserts a "\t" tab character before each item during the send portion
(which I can see when I turn on debug).  The end result is that I
don't get any body or subject in my emails.  It works fine when I copy
the inside of the function and run it directly.  It isn't a
dealbreaker, I can certainly just call it direct, but from a learning
Python perspective I'm wondering if anyone knows what exactly is
happening.I'm more interested in the why this is happening than a
solution (though that would be great too).  Oh and if you could
explain it to me, with no CS background, that would be even better.

I am working on Windows Vista with Python 2.5.2 (activestate).

Thanks --Joshua

Snip of script (more or less a copy/paste from effbot):
fromaddress = '[EMAIL PROTECTED]'
tolist = ['[EMAIL PROTECTED]','[EMAIL PROTECTED]']
msgsubj = "Hello!"
messagebody = "This message was sent with Python's smtplib."


def send_mail(fromaddress,tolist,msgsubj,messagebody):
import smtplib
SERVER = "mymailserver.mydomain.com"
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (fromaddress, ", ".join(tolist),msgsubj, messagebody)

  ^
The tabs are exactly here.

best is to use the mail package to generate mime compliant
emails and use simple templates - which could in the
easiest form just module level constants like:

stdform="""
Hello %(greeting)s,

this automated email is about %(subject)s ... """

and so on and then you use it with

stdform % dict(greeting='Mr Ed',subject='writing emails')

...

HTH
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


SMTPlib inside function, extra tab

2008-10-07 Thread Hunter
I am writing a script that needs to send some emails.  And I've used
smtplib in the past and it is pretty easy.  But I thought, gee it
would be easier if I could just call it as a function, passing the
from, to, subject, and message text.  So I wrote it up as a function
and it sort of works, but I get a weird error.  When it runs it
inserts a "\t" tab character before each item during the send portion
(which I can see when I turn on debug).  The end result is that I
don't get any body or subject in my emails.  It works fine when I copy
the inside of the function and run it directly.  It isn't a
dealbreaker, I can certainly just call it direct, but from a learning
Python perspective I'm wondering if anyone knows what exactly is
happening.I'm more interested in the why this is happening than a
solution (though that would be great too).  Oh and if you could
explain it to me, with no CS background, that would be even better.

I am working on Windows Vista with Python 2.5.2 (activestate).

Thanks --Joshua

Snip of script (more or less a copy/paste from effbot):
fromaddress = '[EMAIL PROTECTED]'
tolist = ['[EMAIL PROTECTED]','[EMAIL PROTECTED]']
msgsubj = "Hello!"
messagebody = "This message was sent with Python's smtplib."


def send_mail(fromaddress,tolist,msgsubj,messagebody):
import smtplib
SERVER = "mymailserver.mydomain.com"
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (fromaddress, ", ".join(tolist),msgsubj, messagebody)
print message
server = smtplib.SMTP(SERVER)
server.set_debuglevel(1)
server.sendmail(fromaddress, tolist, message)
server.quit()

send_mail(fromaddress, tolist, msgsubj, messagebody)

Output when called from function:
send: 'ehlo twaus-mycomputer.mydomain.local\r\n'
reply: '250-mymailserver.mydomain.com Hello [10.10.10.119]\r\n'
reply: '250-TURN\r\n'
reply: '250-SIZE\r\n'
reply: '250-ETRN\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-DSN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8bitmime\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250-CHUNKING\r\n'
reply: '250-VRFY\r\n'
reply: '250-X-EXPS GSSAPI NTLM LOGIN\r\n'
reply: '250-X-EXPS=LOGIN\r\n'
reply: '250-AUTH GSSAPI NTLM LOGIN\r\n'
reply: '250-AUTH=LOGIN\r\n'
reply: '250-X-LINK2STATE\r\n'
reply: '250-XEXCH50\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: mymailserver.mydomain.com Hello
[10.10.10.119]

TURN
SIZE
ETRN
PIPELINING
DSN
ENHANCEDSTATUSCODES
8bitmime
BINARYMIME
CHUNKING
VRFY
X-EXPS GSSAPI NTLM LOGIN
X-EXPS=LOGIN
AUTH GSSAPI NTLM LOGIN
AUTH=LOGIN
X-LINK2STATE
XEXCH50
OK
send: 'mail FROM:<[EMAIL PROTECTED]> size=159\r\n'
reply: '250 2.1.0 [EMAIL PROTECTED] OK\r\n'
reply: retcode (250); Msg: 2.1.0 [EMAIL PROTECTED] OK
send: 'rcpt TO:<[EMAIL PROTECTED]>\r\n'
reply: '250 2.1.5 [EMAIL PROTECTED] \r\n'
reply: retcode (250); Msg: 2.1.5 [EMAIL PROTECTED]
send: 'rcpt TO:<[EMAIL PROTECTED]>\r\n'
reply: '250 2.1.5 [EMAIL PROTECTED] \r\n'
reply: retcode (250); Msg: 2.1.5 [EMAIL PROTECTED]
send: 'data\r\n'
reply: '354 Start mail input; end with .\r\n'
reply: retcode (354); Msg: Start mail input; end with .
data: (354, 'Start mail input; end with .')
send: "\tFrom: [EMAIL PROTECTED]: [EMAIL PROTECTED], j
[EMAIL PROTECTED]: Hello!\r\n\tThis message was sent
with
Python's smtplib.\r\n\t\r\n.\r\n"
reply: '250 2.6.0
<[EMAIL PROTECTED]>
 Queued mail for delivery\r\n'
reply: retcode (250); Msg: 2.6.0
<[EMAIL PROTECTED]
mydomain.com> Queued mail for delivery
data: (250, '2.6.0
<[EMAIL PROTECTED]
> Queued mail for delivery')
send: 'quit\r\n'
reply: '221 2.0.0 mymailserver.mydomain.com Service closing
transmission
channel\r\n'
reply: retcode (221); Msg: 2.0.0 mymailserver.mydomain.com Service
closin
g transmission channel
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED], [EMAIL PROTECTED]
Subject: Hello!
This message was sent with Python's smtplib.

Output if you just run the internal part of the function directly:
send: 'ehlo twaus-mycomputer.mydomain.local\r\n'
reply: '250-mymailserver.mydomain.com Hello [10.10.10.119]\r\n'
reply: '250-TURN\r\n'
reply: '250-SIZE\r\n'
reply: '250-ETRN\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-DSN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8bitmime\r\n'
reply: '250-BINARYMIME\r\n'
reply: '250-CHUNKING\r\n'
reply: '250-VRFY\r\n'
reply: '250-X-EXPS GSSA

Re: how to send a "Multiline" mail with smtplib?

2008-06-23 Thread Evan
On Jun 19, 6:12 pm, Lie <[EMAIL PROTECTED]> wrote:
> On Jun 19, 4:02 pm, Justin Ezequiel <[EMAIL PROTECTED]>
> wrote:
>
> > perhaps change html
>
> > body=MIMEText('hello,\r\n
> > ok',_subtype='html',_charset='windows-1255')
>
> > to plain
>
> > body=MIMEText('hello,\r\n
> > ok',_subtype='plain',_charset='windows-1255')
>
> If that was the case, and you needed a line break in html-mode, use
>  or  tags.


Thanks all,
and yes, if I use "plain" or use HTML tag "", it worked:
(1) HTML:
I use tag "" and " ", and when I reply that mail, I will
see "" tag in mail content, it is not a good option.


thanks,
Evan
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Lie
On Jun 19, 4:02 pm, Justin Ezequiel <[EMAIL PROTECTED]>
wrote:
> perhaps change html
>
> body=MIMEText('hello,\r\n
> ok',_subtype='html',_charset='windows-1255')
>
> to plain
>
> body=MIMEText('hello,\r\n
> ok',_subtype='plain',_charset='windows-1255')

If that was the case, and you needed a line break in html-mode, use
 or  tags.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Justin Ezequiel
perhaps change html

body=MIMEText('hello,\r\n
ok',_subtype='html',_charset='windows-1255')

to plain

body=MIMEText('hello,\r\n
ok',_subtype='plain',_charset='windows-1255')
--
http://mail.python.org/mailman/listinfo/python-list


[SMTPLIB] how to send a "Multiline" mail with smtplib?

2008-06-19 Thread Evan
Hello -

I'm new with Python, I try to do a mail problem, the code likes below:

+

import smtplib
import mimetypes
from email.Encoders import encode_base64
from email.MIMEAudio import MIMEAudio
from email.MIMEBase import MIMEBase
from email.MIMEImage import MIMEImage
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText


msg = MIMEMultipart()
msg['From'] = '[EMAIL PROTECTED]'
msg['To'] = '[EMAIL PROTECTED]'
msg['Subject'] = 'test subject'

body=MIMEText('hello,\r\n ok',_subtype='html',_charset='windows-1255')
msg.attach(body)

server = smtplib.SMTP('mail.xx.net')
server.sendmail('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', msg.as_string())
server.quit()


+++

I try to use "\r\n" or "\n", but no luck, nothing with them, I still
get a Single-line text in the mail.

hello, ok


So how do I send a multiline mail? such as :
+++
Hello,
1,
2,
ok
+++

I would like to get help from you, thanks so much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib "authentication required" error

2008-05-17 Thread 7stud
On May 17, 12:18 pm, cher <[EMAIL PROTECTED]> wrote:
> Hey,
>
> Don't know if you can help, but I'm trying to import archived messages
> from Thunderbird into my gmail account and keep getting these types of
> errors.  I am using the GML program to help incorporate, but the SMTP
> server is not being recognized by gmail.  Am I doing something wrong?  
> Anything else I can try?
> SMTP I've tried:
>     smtp.gmail.com
>     gsmtp56.google.com
>
> Error Val : (530, '5.7.0 Must issue a STARTTLS command first.
> m29sm9416768poh.4',
> *** 76 ERROR SENDING MESSAGE FROM: [EMAIL PROTECTED]
> *** UNABLE TO CONNECT TO SERVER OR SEND MESSAGE. ERROR FOLLOWS.
> Error Type: smtplib.SMTPSenderRefused
> Error Val : (530, '5.7.0 Must issue a STARTTLS command first.
> n22sm9448670pof.3', '[EMAIL PROTECTED]')
>
> Thanks,
> Cher

Can you get the following program to work?


#Uses gmail to send an email to someone

import smtplib

sender = "Tom"
to = "Sally"
subject = "Test smtplib"

headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to,
subject)
msg = headers + "Hello.  How are you?"

mailserver = smtplib.SMTP("smtp.gmail.com", 587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login("your_gmail_email_address", "your_gmail_password")
mailserver.sendmail("your_gmail_email_addres",
"a_destination_email_address", msg)
mailserver.close()

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


smtplib "authentication required" error

2008-05-17 Thread cher

Hey,

Don't know if you can help, but I'm trying to import archived messages 
from Thunderbird into my gmail account and keep getting these types of 
errors.  I am using the GML program to help incorporate, but the SMTP 
server is not being recognized by gmail.  Am I doing something wrong?  
Anything else I can try?

SMTP I've tried:
   smtp.gmail.com
   gsmtp56.google.com

Error Val : (530, '5.7.0 Must issue a STARTTLS command first. 
m29sm9416768poh.4',

*** 76 ERROR SENDING MESSAGE FROM: [EMAIL PROTECTED]
*** UNABLE TO CONNECT TO SERVER OR SEND MESSAGE. ERROR FOLLOWS.
Error Type: smtplib.SMTPSenderRefused
Error Val : (530, '5.7.0 Must issue a STARTTLS command first. 
n22sm9448670pof.3', '[EMAIL PROTECTED]')


Thanks,
Cher


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


Re: Problem with smtplib and py2exe

2008-04-08 Thread Mike Driscoll
On Apr 8, 10:17 am, Kevin <[EMAIL PROTECTED]> wrote:
> Thanks, Terry, you pointed me in the right direction with the
> reference to the "DEBUG".
>
> I dug out my "Learning Python" book, to read up on the debugger, and
> one of the things I came across was a section on IDLE's debugger. It
> said essentially that if you get an error that doesn't make sense when
> you're trying to run another program (in this case, py2exe) with IDLE,
> then run the program from the command line instead.  I did that, and
> much to my surprise, I was able to generate the 'exe' that I needed.
>
> I guess the incompatibility isn't necessarily between 'py2exe' and
> 'smtplib' after all, but between 'py2exe' and 'IDLE'.

I also recommend trying out GUI2Exe, a cool GUI wrapper for the py2exe
program that allows developers to create executables quickly and
easily. It also saves all your settings, which is nice if you need to
re-compile frequently.

I found it here: http://xoomer.alice.it/infinity77/main/GUI2Exe.html

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


Re: Problem with smtplib and py2exe

2008-04-08 Thread Kevin
Thanks, Terry, you pointed me in the right direction with the
reference to the "DEBUG".

I dug out my "Learning Python" book, to read up on the debugger, and
one of the things I came across was a section on IDLE's debugger. It
said essentially that if you get an error that doesn't make sense when
you're trying to run another program (in this case, py2exe) with IDLE,
then run the program from the command line instead.  I did that, and
much to my surprise, I was able to generate the 'exe' that I needed.

I guess the incompatibility isn't necessarily between 'py2exe' and
'smtplib' after all, but between 'py2exe' and 'IDLE'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with smtplib and py2exe

2008-04-07 Thread Terry Reedy

"Kevin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hi everyone,
|
| I'm running Python 2.5.1 on an XP-Pro platform, with all the updates
| (SP2, etc) installed. I have a program (send_file.py) that sends a
| file to a service provider, using an ftp connection.  The program
| works properly, and I've created an 'exe' of it, using py2exe.  It was
| distrubuted to my user base a couple of weeks ago and seems to be
| working well.  None of the users have Python installed on their
| machines, thus the need for an 'exe' for the program.
|
| I now need to add an email function to the program, to automatically
| send an email to a select user list when the program is completed.
| I've made the appropriate modifications to my code, and the program
| works properly when I run it from Python.  When I try to make an exe
| out of my new program, however, I get the following error:
|
| Traceback (most recent call last):
|  File "C:/Python25/send_ftp/setup.py", line 17, in 
|console = [{"script": 'send_file.py'}] )
|  File "C:\Python25\lib\distutils\core.py", line 168, in setup
|raise SystemExit, "error: " + str(msg)

I would go to that line in that file (it is in the except: part of a try: 
statement) and file the function call that raised the exception and ...
There seems to be a DEBUG variable, which might also give more info.

| SystemExit: error: command 'C:\Python25\pythonw.exe' failed with exit
| status 1
|
| The 'setup.py' script is the same one I used to generate the 'exe' of
| the original program. The email-related code was added to my
| 'send_file.py' program as a function - it's not a separate module.  If
| all of the changes are commented out, the py2exe function works. But
| as soon as I activate even the line "import smtplib", the py2exe
| process spits out the error above.
|
| If I put only the email portions of code in a test program, and run it
| from Python, it works, but if I try make an 'exe' out of the test
| program, I get the same error as above.
|
| Is there an inherent incompatibility between smtplib and py2exe? Does
| anyone have any ideas of how I can fix this problem?

tjr



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


Problem with smtplib and py2exe

2008-04-07 Thread Kevin
Hi everyone,

I'm running Python 2.5.1 on an XP-Pro platform, with all the updates
(SP2, etc) installed. I have a program (send_file.py) that sends a
file to a service provider, using an ftp connection.  The program
works properly, and I've created an 'exe' of it, using py2exe.  It was
distrubuted to my user base a couple of weeks ago and seems to be
working well.  None of the users have Python installed on their
machines, thus the need for an 'exe' for the program.

I now need to add an email function to the program, to automatically
send an email to a select user list when the program is completed.
I've made the appropriate modifications to my code, and the program
works properly when I run it from Python.  When I try to make an exe
out of my new program, however, I get the following error:

Traceback (most recent call last):
  File "C:/Python25/send_ftp/setup.py", line 17, in 
console = [{"script": 'send_file.py'}] )
  File "C:\Python25\lib\distutils\core.py", line 168, in setup
raise SystemExit, "error: " + str(msg)
SystemExit: error: command 'C:\Python25\pythonw.exe' failed with exit
status 1

The 'setup.py' script is the same one I used to generate the 'exe' of
the original program. The email-related code was added to my
'send_file.py' program as a function - it's not a separate module.  If
all of the changes are commented out, the py2exe function works. But
as soon as I activate even the line "import smtplib", the py2exe
process spits out the error above.

If I put only the email portions of code in a test program, and run it
from Python, it works, but if I try make an 'exe' out of the test
program, I get the same error as above.

Is there an inherent incompatibility between smtplib and py2exe? Does
anyone have any ideas of how I can fix this problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib & gnupg

2008-02-20 Thread Miki
Hello Bernd,

> at the moment my program sends mail with smtplib. Is there a chance to
> sign and/or encode/cipher this mails with GnuPG?
> If yes, does anyone have some sample code?
Not exactly Python, but maybe http://codesorcery.net/old/mutt/mutt-gnupg-howto
might help.

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com

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


Re: smtplib & gnupg

2008-02-20 Thread Shane Geiger
To the best of my knowledge, GNUPG acts upon the body of the message. 
If you think about it you should realize that the header of the message
cannot be encrypted, as it will be handled by mail servers that have no
knowledge of GNUPG or your encryption keys.  I am further emboldened to
make this assertion because the encryption takes place before the
message is sent--that is, before the headers are completely formed.



Brot wrote:
> Hello,
>
> at the moment my program sends mail with smtplib. Is there a chance to
> sign and/or encode/cipher this mails with GnuPG?
> If yes, does anyone have some sample code?
>
> Regards
>   Bernd
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


smtplib & gnupg

2008-02-20 Thread Brot
Hello,

at the moment my program sends mail with smtplib. Is there a chance to
sign and/or encode/cipher this mails with GnuPG?
If yes, does anyone have some sample code?

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


Re: [HELP] SMTPlib not sending my mail

2008-01-29 Thread ashok raavi
i  checked it after your mail..

it is giving the following warning: no entropy for TLS key generation:
disabling TLS support

which was addressed here "
http://www.howtoforge.com/forums/showthread.php?t=781";

after adding the line "tlsmgr unix - - n 1000? 1 tlsmgr"  to
/etc/postfix/master.cf it started working.

Thank you.


On 1/29/08, Lars Johansen <[EMAIL PROTECTED]> wrote:
>
> have you checked your mail server logs ?
>
> tir, 29.01.2008 kl. 00.24 -0800, skrev ashok.raavi:
> > Hi,
> >
> > I am also facing the same problem, smtplib used to send mail a while
> > back but it stopped sending mails.
> >
> > when i run this in interpreter
> > >>> import smtplib
> > >>> s = smtplib.SMTP("localhost")
> > >>> s.sendmail(from, to, "message")
> > {}
> > >>>
> >
> > though it is not giving any error, it is not sending mail.
> >
> > Any help is appreciated.
> >
> > ornto wrote:
> > > Hi, I'm trying to create an application which checks a
> > > dynamic web site and on certain events sends an email to me.
> > > My problem though is with the email task. By now I made this
> > >   simple test code:
> > >
> > > #prova invio email
> > > smtpserver = smtplib.SMTP(mailserver)
> > > messaggio= "Messaggio di prova"
> > > print mail
> > > print messaggio
> > > smtpresult=smtpserver.sendmail("Watcher",mail,messaggio)
> > > if smtpresult:
> > >  print smtpresult
> > > smtpserver.quit()
> > >
> > > "mailserver" and "mail" values are loaded from a ini file
> > > and they're correct.
> > > The call to smtpserver gives back no errors (smtpresult
> > > remains empty).
> > > The running enviroment gives no error.
> > > So, it looks like that the program works alloright, sending
> > > the mail- BUT, I receive no mail! I've tried to change the
> > > smtp server with another one which still works with my isp,
> > > with no luck. If I try a smtp which doesn't give me access,
> > > I correctly receive an error from the program.
> > > What might be the problem?
>
>


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

Re: [HELP] SMTPlib not sending my mail

2008-01-29 Thread Lars Johansen
have you checked your mail server logs ?

tir, 29.01.2008 kl. 00.24 -0800, skrev ashok.raavi:
> Hi,
> 
> I am also facing the same problem, smtplib used to send mail a while
> back but it stopped sending mails.
> 
> when i run this in interpreter
> >>> import smtplib
> >>> s = smtplib.SMTP("localhost")
> >>> s.sendmail(from, to, "message")
> {}
> >>>
> 
> though it is not giving any error, it is not sending mail.
> 
> Any help is appreciated.
> 
> ornto wrote:
> > Hi, I'm trying to create an application which checks a
> > dynamic web site and on certain events sends an email to me.
> > My problem though is with the email task. By now I made this
> >   simple test code:
> >
> > #prova invio email
> > smtpserver = smtplib.SMTP(mailserver)
> > messaggio= "Messaggio di prova"
> > print mail
> > print messaggio
> > smtpresult=smtpserver.sendmail("Watcher",mail,messaggio)
> > if smtpresult:
> >  print smtpresult
> > smtpserver.quit()
> >
> > "mailserver" and "mail" values are loaded from a ini file
> > and they're correct.
> > The call to smtpserver gives back no errors (smtpresult
> > remains empty).
> > The running enviroment gives no error.
> > So, it looks like that the program works alloright, sending
> > the mail- BUT, I receive no mail! I've tried to change the
> > smtp server with another one which still works with my isp,
> > with no luck. If I try a smtp which doesn't give me access,
> > I correctly receive an error from the program.
> > What might be the problem?

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


Re: [HELP] SMTPlib not sending my mail

2008-01-29 Thread ashok.raavi

Hi,

I am also facing the same problem, smtplib used to send mail a while
back but it stopped sending mails.

when i run this in interpreter
>>> import smtplib
>>> s = smtplib.SMTP("localhost")
>>> s.sendmail(from, to, "message")
{}
>>>

though it is not giving any error, it is not sending mail.

Any help is appreciated.

ornto wrote:
> Hi, I'm trying to create an application which checks a
> dynamic web site and on certain events sends an email to me.
> My problem though is with the email task. By now I made this
>   simple test code:
>
> #prova invio email
> smtpserver = smtplib.SMTP(mailserver)
> messaggio= "Messaggio di prova"
> print mail
> print messaggio
> smtpresult=smtpserver.sendmail("Watcher",mail,messaggio)
> if smtpresult:
>  print smtpresult
> smtpserver.quit()
>
> "mailserver" and "mail" values are loaded from a ini file
> and they're correct.
> The call to smtpserver gives back no errors (smtpresult
> remains empty).
> The running enviroment gives no error.
> So, it looks like that the program works alloright, sending
> the mail- BUT, I receive no mail! I've tried to change the
> smtp server with another one which still works with my isp,
> with no luck. If I try a smtp which doesn't give me access,
> I correctly receive an error from the program.
> What might be the problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


[HELP] SMTPlib not sending my mail

2008-01-21 Thread ornto
Hi, I'm trying to create an application which checks a 
dynamic web site and on certain events sends an email to me. 
My problem though is with the email task. By now I made this 
  simple test code:

#prova invio email
smtpserver = smtplib.SMTP(mailserver)
messaggio= "Messaggio di prova"
print mail
print messaggio
smtpresult=smtpserver.sendmail("Watcher",mail,messaggio)
if smtpresult:
 print smtpresult
smtpserver.quit()

"mailserver" and "mail" values are loaded from a ini file 
and they're correct.
The call to smtpserver gives back no errors (smtpresult 
remains empty).
The running enviroment gives no error.
So, it looks like that the program works alloright, sending 
the mail- BUT, I receive no mail! I've tried to change the 
smtp server with another one which still works with my isp, 
with no luck. If I try a smtp which doesn't give me access, 
I correctly receive an error from the program.
What might be the problem?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: smtplib problem, Unable to relay for

2007-12-26 Thread Benedict Verheyen
Benedict Verheyen schreef:
> 

Thanks for the responses.

I solved it by adjusting the relayers list (i'm a domain admin) in 
others words i granted my pc the rights to relay.
I did this by starting the Exchange System Manager and then going to 
Servers->->protocols->SMTP

Then right click on "Default SMTP Virtual Server" and properties,
go to the Access pane and near the bottom you have a button "Relay"
in a section called "Relay restrictions".
That's where i temporarily added my ip address.

After sending the greetings mail, i removed my ip address again from 
that granted list.

Regards and many thanks,
Benedict



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


Re: smtplib problem, Unable to relay for

2007-12-22 Thread Grant Edwards
On 2007-12-21, Benedict Verheyen <[EMAIL PROTECTED]> wrote:

> i get an "Unable to relay for" when trying to send an email
> from within my network to an email address not on my domain. I
> don't understand why it says "relaying" as i'm sending from an
> internal domain user to an external user.

You're asking the SMTP server to accept mail for a user that's
not local to that server.  That's relaying.

> Email server is exchange 2003

Ah, well, that's too bad.  You can probably get it to work
anyway...

> See this trace
>
> >>> smtp.sendmail("[EMAIL PROTECTED]", ["[EMAIL PROTECTED]"], msg)
> Traceback (most recent call last):
>File "", line 1, in 
>File "C:\Python25\Lib\smtplib.py", line 695, in sendmail
>  raise SMTPRecipientsRefused(senderrs)
> smtplib.SMTPRecipientsRefused: {'[EMAIL PROTECTED]': (550, '5.7.1 
> Unable to relay for [EMAIL PROTECTED]')}
>
> The smpt var is this:
> smtp = smtplib.SMTP(server) where server is my mail server
>
> I can mail to any user that is part of mydomain.be but as soon
> as i try an external address, i get the "Unable to relay"
> message.
>
> With a mail program it works

With what "mail program"?  Outlook?  Outlook doesn't use SMTP
to send mail, so it doesn't matter what works or doesn't work
in Outlook. If relaying does work with other SMTP clients, then
comparing a TCP trace of a program that works with one from a
program that doesn't work would be very informative.

> but i need to be able to do it via code.

You can use Python to send e-mails via Outlook if you want to
do that instead of using SMTP.  However, Microsoft has crippled
Outlook's automation interface in a half-witted and mostly
ineffectual attempt to plug security holes.  So, you have to
jump through a hoop to bypass Microsoft Outlook's security
stuff (it's not really hard to bypass -- big surprise there).
Googling for "python sending mail with outlook" will find you
all sorts of examples.

> I thought that i would have to authenticate (smtp.login) to
> our mail server but that didn't resolve the issue
>
> Any idea how i could do this?

Ask the Exchange admin to enable relaying.  But, (this is
_very_important_) make sure he limits relaying so that it only
relays mail accepted from the _internal_ network.  If you
allowing relaying of mail accepted from outside hosts (to
outside hosts), you'll be used by spammers and criminals for
all sorts of evil, mischief, and crime.

-- 
Grant Edwards   grante Yow!  I'm rated PG-34!!
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >