error while writing program to send mail.

2014-09-01 Thread Om Prakash

Hi,

I am writing this program from 
https://docs.python.org/2/library/email-examples.html


but getting the error as

singhom@debian:~/pythons$ python send_email.py
Traceback (most recent call last):
  File "send_email.py", line 18, in 
msg['Subject']  = 'The contents of $s' % message
NameError: name 'message' is not defined


i know the error would be something simple and i am overlooking it, any 
help would be highly appreciated, I am sorry, but I am very new to 
python programming.


code starts here.
#/usr/bin/python2.7 -tt

## sending a simple text message using python.
import smtplib

from email.mime.text import MIMEText

# Open file for reading.
fp = open("message", 'rb')
# Create a plain text message.
msg = MIMEText(fp.read())

fp.close

me = "[email protected]"
you = "[email protected]"

msg['Subject']  = 'The contents of $s' % message
msg['From'] = me
msg['To'] = you

# Send message thorugh localhost but don't include the envelope headers.

s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()

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


Define proxy in windows 7

2014-09-01 Thread Om Prakash

Hi,

I am wondering how to define proxy setting in env variable on windows 7, 
I want this so i can use pip to pull packages for me, the same setting 
though working earlier on windows xp.


http_proxy = "proxy name:80"

now this same setting doesn't work, i tried doing in the cmd.exe prompt.

set http_proxy "proxy name:80"

P.S. i am a normal user and don't have admin privleges.

Regards,
Om Prakash
--
https://mail.python.org/mailman/listinfo/python-list


Re: error while writing program to send mail.

2014-09-01 Thread Om Prakash

On 09/02/2014 05:29 AM, MRAB wrote:

On 2014-09-02 00:35, Om Prakash wrote:

Hi,

I am writing this program from
https://docs.python.org/2/library/email-examples.html

but getting the error as

singhom@debian:~/pythons$ python send_email.py
Traceback (most recent call last):
File "send_email.py", line 18, in 
  msg['Subject']  = 'The contents of $s' % message
NameError: name 'message' is not defined


i know the error would be something simple and i am overlooking it, any
help would be highly appreciated, I am sorry, but I am very new to
python programming.

code starts here.
#/usr/bin/python2.7 -tt

## sending a simple text message using python.
import smtplib

from email.mime.text import MIMEText

# Open file for reading.
fp = open("message", 'rb')
# Create a plain text message.
msg = MIMEText(fp.read())

fp.close


That should be:

fp.close()



me = "[email protected]"
you = "[email protected]"

msg['Subject']  = 'The contents of $s' % message


You're trying to use the format operator, but:

1. You never bound the name 'message' to a value, hence:

NameError: name 'message' is not defined

2. The format string contains '$s' instead of '%s'.


msg['From'] = me
msg['To'] = you

# Send message thorugh localhost but don't include the envelope headers.

s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()




Thanks a lot. will fix this and my overlooking of things too. :)
--
https://mail.python.org/mailman/listinfo/python-list