Re: [Tutor] Mail? What's that?

2007-12-06 Thread Ricardo Aráoz
Justin Cardinal wrote:
> Ricardo Aráoz wrote:
> 
>>Are From: To: Date: and Subject: mandatory in the contents of the
>>email(text)?  Do I have to put "real" address in  From when calling
>>sendmail()? And in the contents?
> 
> Here's the page I used to learn on this subject.
> http://www.thinkspot.net/sheila/article.php?story=20040822174141155
>  
> I'm definitely not a pro in this area, so what comes next are merely
> assumptions made after toying around a bit.
> I don't believe the From, To, Date, Subject are required, but if you
> play around sending some test messages to yourself, you'll see that
> excluding them makes the message look very suspicious. As far as using
> your real address, that might depend on your email server...but yes, you
> can most likely spoof other addresses. Please use this for good, not evil.
>  
> -Justin Cardinal

Thanks Justin.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Mail? What's that?

2007-12-06 Thread Justin Cardinal

Ricardo Aráoz wrote:
>Are From: To: Date: and Subject: mandatory in the contents of the

>email(text)?  Do I have to put "real" address in  From when calling

>sendmail()? And in the contents?
Here's the page I used to learn on this subject.
http://www.thinkspot.net/sheila/article.php?story=20040822174141155
 
I'm definitely not a pro in this area, so what comes next are merely
assumptions made after toying around a bit.
I don't believe the From, To, Date, Subject are required, but if you play
around sending some test messages to yourself, you'll see that excluding
them makes the message look very suspicious. As far as using your real
address, that might depend on your email server...but yes, you can most
likely spoof other addresses. Please use this for good, not evil.
 
-Justin Cardinal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mail? What's that?

2007-12-06 Thread Ricardo Aráoz
Luke Paireepinart wrote:
> Ricardo Aráoz wrote:
>> So I eventually got to sending mail with python.
>> Some articles, trying and google led me to this script:
>>
>> import smtplib
>> import time
>>
>> date = time.ctime(time.time( ))
>> >From = '[EMAIL PROTECTED]'
>> To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]']
>> Subj = 'Hi'
>> text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
>>  % (From, ';'.join(To), date, Subj))
>>
>> s = smtplib.SMTP('smtp.gmail.com')
>> s.set_debuglevel(1)
>> s.ehlo()
>> s.starttls()
>> s.ehlo()
>> s.login('foo', 'bar')
>> s.sendmail(From, To, text)
>> s.close()
>>
>>
>> So, if there's someone who really knows this stuff in the neighborhood
>> I'd like to ask a couple of questions.
>> What is ehlo and why do I have to call it twice? And set_debuglevel?
>> If I where to connect through other smtp server the sequence would be
>> the exactly the same, say yahoo or hotmail?
>> Are From: To: Date: and Subject: mandatory in the contents of the
>> email(text)?  Do I have to put "real" address in  From when calling
>> sendmail()? And in the contents?
>> Ok, if someone can answer these I'll be grateful.
>>
>> TIA
>>
>> Ricardo
>>   
> Ricardo -
> I say this in the nicest way possible, but did you RTFM? :)

LOL, my apologies Luke. You see, I was bloody tired last night, had just
found out how to do it and didn´t have it in me to google for it or
RTFM, so I said "let's ask the guys". Sorry, and thanks a lot for taking
the time to answer me. I'm just rushing out to work so I'll take a look
tonight and see if I get it, I'm net impaired you see, and when they
start with all those acronyms my brain stops :-)
Thanks again.

Ricardo

> Python has built-in help support on modules.
> You should start there, do some Googling, and if you're stumped, get
> some help.  Not for any other reason than it'll probably get you 1) more
> experience at navigating the docs, and 2) a quicker, probably more
> detailed response.
> 
> So using Help, we get:
> 
> 
 import smtplib
 help(smtplib)
> Help on module smtplib:
> 
> NAME
>smtplib - SMTP/ESMTP client class.
> 
> FILE
>c:\python24\lib\smtplib.py
> 
> [snip 10 pages of documentation]
> 
> 
 help(smtplib.SMTP.set_debuglevel)
> Help on method set_debuglevel in module smtplib:
> 
> set_debuglevel(self, debuglevel) unbound smtplib.SMTP method
>Set the debug output level.
>  A non-false value results in debug messages for connection and for all
>messages sent to and received from the server.
> 
 help(smtplib.SMTP.ehlo)
> Help on method ehlo in module smtplib:
> 
> ehlo(self, name='') unbound smtplib.SMTP method
>SMTP 'ehlo' command.
>Hostname to send for this command defaults to the FQDN of the local
>host.
> 
 help(smtplib.SMTP.sendmail)
> Help on method sendmail in module smtplib:
> 
> sendmail(self, from_addr, to_addrs, msg, mail_options=[],
> rcpt_options=[]) unbound smtplib.SMTP method
>This command performs an entire mail transaction.
>  The arguments are:
>- from_addr: The address sending this mail.
>- to_addrs : A list of addresses to send this mail to.  A bare
> string will be treated as a list with 1 address.
>- msg  : The message to send.
>- mail_options : List of ESMTP options (such as 8bitmime) for the
> mail command.
>- rcpt_options : List of ESMTP options (such as DSN commands) for
> all the rcpt commands.
>  If there has been no previous EHLO or HELO command this session, this
>method tries ESMTP EHLO first.  If the server does ESMTP, message size
>and each of the specified options will be passed to it.  If EHLO
>fails, HELO will be tried and ESMTP options suppressed.
>  This method will return normally if the mail is accepted for at least
>one recipient.  It returns a dictionary, with one entry for each
>recipient that was refused.  Each entry contains a tuple of the SMTP
>error code and the accompanying error message sent by the server.
>  This method may raise the following exceptions:
>   SMTPHeloError  The server didn't reply properly to
>the helo greeting.
> SMTPRecipientsRefused  The server rejected ALL recipients
>(no mail was sent).
> SMTPSenderRefused  The server didn't accept the from_addr.
> SMTPDataError  The server replied with an unexpected
>error code (other than a refusal of
>a recipient).
>  Note: the connection will be open even after an exception is raised.
>  Example:
>   >>> import smtplib
> >>> s=smtplib.SMTP("localhost")
> >>>
> tolist=["[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL 
> PROTECTED]"]
> >>> msg = '''\
> ... From: [EMAIL PROTECTED]
> ... Subject: testin'...
> ...
> 

Re: [Tutor] Mail? What's that?

2007-12-05 Thread Luke Paireepinart
Ricardo Aráoz wrote:
> So I eventually got to sending mail with python.
> Some articles, trying and google led me to this script:
>
> import smtplib
> import time
>
> date = time.ctime(time.time( ))
> >From = '[EMAIL PROTECTED]'
> To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]']
> Subj = 'Hi'
> text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
>  % (From, ';'.join(To), date, Subj))
>
> s = smtplib.SMTP('smtp.gmail.com')
> s.set_debuglevel(1)
> s.ehlo()
> s.starttls()
> s.ehlo()
> s.login('foo', 'bar')
> s.sendmail(From, To, text)
> s.close()
>
>
> So, if there's someone who really knows this stuff in the neighborhood
> I'd like to ask a couple of questions.
> What is ehlo and why do I have to call it twice? And set_debuglevel?
> If I where to connect through other smtp server the sequence would be
> the exactly the same, say yahoo or hotmail?
> Are From: To: Date: and Subject: mandatory in the contents of the
> email(text)?  Do I have to put "real" address in  From when calling
> sendmail()? And in the contents?
> Ok, if someone can answer these I'll be grateful.
>
> TIA
>
> Ricardo
>   
Ricardo -
I say this in the nicest way possible, but did you RTFM? :)
Python has built-in help support on modules.
You should start there, do some Googling, and if you're stumped, get 
some help.  Not for any other reason than it'll probably get you 1) more 
experience at navigating the docs, and 2) a quicker, probably more 
detailed response.

So using Help, we get:


 >>> import smtplib
 >>> help(smtplib)
Help on module smtplib:

NAME
smtplib - SMTP/ESMTP client class.

FILE
c:\python24\lib\smtplib.py

[snip 10 pages of documentation]


 >>> help(smtplib.SMTP.set_debuglevel)
Help on method set_debuglevel in module smtplib:

set_debuglevel(self, debuglevel) unbound smtplib.SMTP method
Set the debug output level.
   
A non-false value results in debug messages for connection and for all
messages sent to and received from the server.

 >>> help(smtplib.SMTP.ehlo)
Help on method ehlo in module smtplib:

ehlo(self, name='') unbound smtplib.SMTP method
SMTP 'ehlo' command.
Hostname to send for this command defaults to the FQDN of the local
host.

 >>> help(smtplib.SMTP.sendmail)
Help on method sendmail in module smtplib:

sendmail(self, from_addr, to_addrs, msg, mail_options=[], 
rcpt_options=[]) unbound smtplib.SMTP method
This command performs an entire mail transaction.
   
The arguments are:
- from_addr: The address sending this mail.
- to_addrs : A list of addresses to send this mail to.  A bare
 string will be treated as a list with 1 address.
- msg  : The message to send.
- mail_options : List of ESMTP options (such as 8bitmime) for the
 mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
 all the rcpt commands.
   
If there has been no previous EHLO or HELO command this session, this
method tries ESMTP EHLO first.  If the server does ESMTP, message size
and each of the specified options will be passed to it.  If EHLO
fails, HELO will be tried and ESMTP options suppressed.
   
This method will return normally if the mail is accepted for at least
one recipient.  It returns a dictionary, with one entry for each
recipient that was refused.  Each entry contains a tuple of the SMTP
error code and the accompanying error message sent by the server.
   
This method may raise the following exceptions:
   
 SMTPHeloError  The server didn't reply properly to
the helo greeting.
 SMTPRecipientsRefused  The server rejected ALL recipients
(no mail was sent).
 SMTPSenderRefused  The server didn't accept the from_addr.
 SMTPDataError  The server replied with an unexpected
error code (other than a refusal of
a recipient).
   
Note: the connection will be open even after an exception is raised.
   
Example:
   
 >>> import smtplib
 >>> s=smtplib.SMTP("localhost")
 >>> 
tolist=["[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL 
PROTECTED]"]
 >>> msg = '''\
 ... From: [EMAIL PROTECTED]
 ... Subject: testin'...
 ...
 ... This is a test '''
 >>> s.sendmail("[EMAIL PROTECTED]",tolist,msg)
 { "[EMAIL PROTECTED]" : ( 550 ,"User unknown" ) }
 >>> s.quit()
   
In the above example, the message was accepted for delivery to three
of the four addresses, and one was rejected, with the error code
550.  If all addresses are accepted, then the method will return an
empty dictionary.

 >>>




So mess around in the built-in docs, then check python.org's docs, and 
let us know what you find :)
Also, try experimenting! pass it stuff that you don't think will work 
just to s

[Tutor] Mail? What's that?

2007-12-05 Thread Ricardo Aráoz
So I eventually got to sending mail with python.
Some articles, trying and google led me to this script:

import smtplib
import time

date = time.ctime(time.time( ))
>From = '[EMAIL PROTECTED]'
To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]']
Subj = 'Hi'
text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
 % (From, ';'.join(To), date, Subj))

s = smtplib.SMTP('smtp.gmail.com')
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.ehlo()
s.login('foo', 'bar')
s.sendmail(From, To, text)
s.close()


So, if there's someone who really knows this stuff in the neighborhood
I'd like to ask a couple of questions.
What is ehlo and why do I have to call it twice? And set_debuglevel?
If I where to connect through other smtp server the sequence would be
the exactly the same, say yahoo or hotmail?
Are From: To: Date: and Subject: mandatory in the contents of the
email(text)?  Do I have to put "real" address in  From when calling
sendmail()? And in the contents?
Ok, if someone can answer these I'll be grateful.

TIA

Ricardo


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor