[Tutor] email-sending.. (fwd)

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Jan 29 19:09:17 CET 2006



---------- Forwarded message ----------
Date: Sun, 29 Jan 2006 10:28:09 -0500 (EST)
From: jan.n <jndomain at yahoo.com>
To: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] email-sending..

Hi Danny,

i have crossed that point where it complains of socket error.., but now i am stuck with another issue, where it says that it has sent the mail, but i dont recive any in my yahoo mail.,i have even unbloked my spam filter in my yahoo..

i am a begginer in python scripting,i will paste the scipt i am usinh now..

this the code that i run...

this is a command line code though, i need a script that launches from a shell, with a command, any help would be appritiated.

######################################################
# use the Python SMTP mail interface module to send
# email messages; this is just a simple one-shot
# send script--see pymail, PyMailGui, and PyMailCgi
# for clients with more user interaction features,
# and popmail.py for a script which retrieves mail;
######################################################

import smtplib, string, sys, time, mailconfig

mailserver = mailconfig.smtpservername         # ex: starship.python.net

>From = string.strip(raw_input('From? '))       # ex: lutz at rmi.net
To   = string.strip(raw_input('To?   '))       # ex: python-list at python.org
To   = string.split(To, ';')                   # allow a list of recipients
Subj = string.strip(raw_input('Subj? '))

# prepend standard headers
date = time.ctime(time.time())
text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n'
                         % (From, string.join(To, ';'), date, Subj))

print 'Type message text, end with line=(ctrl + D or Z)'
while 1:
    line = sys.stdin.readline()
    if not line:
        break                        # exit on ctrl-d/z
  # if line[:4] == 'From':
  #     line = '>' + line            # servers escape for us
    text = text + line

if sys.platform[:3] == 'win': print
print 'Connecting...'
server = smtplib.SMTP(mailserver)              # connect, no login step
failed = server.sendmail(From, To, text)
server.quit()
if failed:                                     # smtplib may raise exceptions
    print 'Failed recipients:', failed         # too, but let them pass here
else:
    print 'No errors.'
print 'Bye.'



and this is the code for mailconfig....


############################################
# email scripts get server names from here:
# change to reflect your machine/user names;
# could get these in command line instead
############################################

# SMTP email server machine (send)
smtpservername = 'localhost'          # or starship.python.net, 'localhost'

# POP3 email server machine, user (retrieve)
popservername  = 'localhost'     # or starship.python.net, 'localhost'
popusername    = 'username'       # password is requested when run
poppassword = 'mypassword'

# local file where pymail (not PyMailGui) saves pop mail
savemailfile   = r'c:\Temp\savemail.txt'

# personal info used by PyMailGui to fill in forms;
# sig-- can be a triple-quoted block, ignored if empty string;
# addr--used for initial value of "From" field if not empty,
# else tries to guess From for replies, with varying success;

myaddress   = 'jndomain at yahoo.com'
mysignature = 'jan  (http://jandomain3d.com)  [PyMailCgi 1.0]'


Jan.


Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:

Hi Jan,

Side question: how much Python do you know already?  It really seems like
you've just picked up an introductory example, so I'm not exactly sure I
see where you might be getting stuck or what things you've tried already.


Anyway, when you mention:

> i am trying to send emails through a python script , but it complains that
>
> socket error 10061 conection refused..

although this is useful, you should also copy-and-paste the exact error
message.  I know that you have to be paraphrasing somewhere because the
word "connection" is misspelled above.


Copying-and-pasting error messages is perfectly fine: they provide
information in even their most trivial-looking details, which is why we
really want to see that information in its fullness.


It will also help to see at one line things start going wrong.  Do you
remember seeing any kind of stack trace that pointed out which line of the
program wasn't going so well?



On quick question about the program you're showing us:

> smtpserver = 'mailserver'
                ^^^^^^^^^^

Is this the real name of your SMTP mail server?




---------------------------------
Find your next car at Yahoo! Canada Autos



More information about the Tutor mailing list