SMTP via GMAIL

sui gogtesuyash at gmail.com
Wed Sep 17 08:23:53 EDT 2008


On Aug 7, 12:40 am, mmm <mdbol... at gmail.com> wrote:
> On Aug 5, 12:18 am, Tim Roberts <t... at probo.com> wrote:
>
> > >But when using smtp.gmail.com as the server I learned that any
> > >@gmail.com address in the  Cc: text block would
> > >receive mail even if I changed the code to have the RECEIVERS list to
> > >ignore the CC addresses or not include the gmail address in the CC
> > >list as below
>
> > Interesting.  If true, that is incorrect behavior.
>
> I ran some more tests and now I am pretty sure
>
>   session.sendmail(SENDER, RECEIVERS, BODY)
>
> is only sending to the RECEIVERS list, ignoring the Cc: field in the
> body (as it should)
>
> What fooled me is that I was using my own gmail account (i.e.,
> m... at gmail.com) as a Cc: field and not putting it in the RECEIVERS
> list.  It seems Gmail creates two links (or copies?) to the message:
> (1) as it is stored in the SENT box (as it should since the message
> was sent by my gmail account) and (2) another in my INBOX because the
> mail reading software reads the Cc: field.
>
> Other smtp servers such as comcast do not create the stored SENT mail
> and hence behave different in terms of how they treat Cc: fields of
> the same account (m... at comcast.net in this case).
>
> Most important, using another gmail account (not m... at gmail.com) as a
> Cc: field does not create another sent message (outside of what is in
> the RECEIVERS field).
>
> Sorry for confusion, and I do appreciate the tips as I now see how
> almost anything To:, Cc:, Bcc: combination can be handled by a proper
> RECEIVERS list.
>
> Below is python code that can be used by anyone that wants to test
> what I did  (just fill in the SMTPuser and password variables) and
> then check you gmail inbox
>
> import sys, os, glob, datetime, time
> import smtplib
> ## Parameters for SMTP session
> port=587
> SMTPserver=  'smtp.gmail.com'
> SMTPuser= '... at gmail.com'
> pw= 'fill in here'
> SENDER= SMTPuser
>
> ## Message details
> FROM=  SENDER
> TO= 'notgm... at a.com'
> CC=FROM
> ##RECEIVERS= (TO, CC)  ##proper way to send to both TO and CC
> RECEIVERS= (TO,)  ## ignore the CC address
>
> subject= 'Test 1a'
> message='*** Email test  *** '
>
> print 'Starting SMTP mail session on %s as  %s ' %
> (SMTPserver,SMTPuser)
> session = smtplib.SMTP(SMTPserver,port)
> session.set_debuglevel(0)  # set debug level to 1 to see details
> session.ehlo(SMTPuser)  # say hello
> session.starttls()  # TLS needed
> session.ehlo(SMTPuser)  # say hello again, not sure why
> session.login(SMTPuser, pw)
>
> ##Create HEADER + MESSAGE
> HEADER= 'From: %s\r\n' % FROM
> HEADER= HEADER + 'To: %s\r\n' % TO
> HEADER= HEADER + 'Cc: %s\r\n' % CC
> HEADER= HEADER + 'Subject: %s\r\n' % subject
> BODY= HEADER + '\r\n' + message
> print BODY
>
> SMTPresult = session.sendmail(SENDER, RECEIVERS, BODY)  ## send email
>
> session.close()

i tried to run this code...but it didnt work
it shows that message like starting smtp session
then it doesnt show anything after very long time it shows
Traceback (most recent call last):
  File "mail5.py", line 21, in <module>
    session = smtplib.SMTP(SMTPserver,port)
  File "/usr/local/lib/python2.5/smtplib.py", line 244, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python2.5/smtplib.py", line 301, in connect
    self.sock.connect(sa)
  File "<string>", line 1, in connect
then conncetion time out.....
can u tell me wats the prob ...plz tell me solun



More information about the Python-list mailing list