Newbie CGI confusion...

Discussion in 'Python' started by Fred Mailhot, Feb 19, 2004.

  1. Fred Mailhot

    Fred Mailhot Guest

    I'm trying to write a script that will mail some data from a web-based form
    to me, using the "mail" command (under Linux). The following illustrates the
    crux of what I'm doing:


    #!/usr/bin/python

    import os,time,cgi

    #################################
    # get the data from the form #
    #################################
    formdata = cgi.FieldStorage()

    #################################
    # open log file & write header #
    #################################
    logfile = open('<SOME FILE>','a')
    logfile.write('\n*************************** ')
    logfile.write(time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.localtime()))
    logfile.write(' ***************************\n')


    ####################
    # send data to log #
    ####################
    for name in formdata.keys():
    logfile.write(formdata[name].value + '\n')


    #########################################
    # create shell command to send mail #
    #########################################
    usrmail = "%s" % formdata['email'].value
    usrmesg = "Sender: %s\n\n%s" % (formdata['user'].value,
    formdata['comments'].value)
    ccaddr = ""
    subject = "SMT Website User Feedback"
    toaddr = ""

    cmdstring = 'mail -c %s -s "%s" -r %s %s' % (ccaddr, subject, usrmail,
    toaddr)

    os.popen(cmdstring,'w').write(usrmesg)

    ######## end code snippet #############

    So. The script works and the relevant information is mailed, EXCEPT that the
    body of the message is included as an attachment of unknown type. When I
    execute the shell command from the command line, there's no problem.

    Why is Python doing this ?? (or is it something else entirely that I'm not
    understanding?)


    Many thanks,

    Fred.
     
    Fred Mailhot, Feb 19, 2004
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shailan
    Replies:
    2
    Views:
    1,439
    Shailan
    Dec 15, 2003
  2. John Smith
    Replies:
    0
    Views:
    3,425
    John Smith
    May 15, 2006
  3. LarsenMTL
    Replies:
    4
    Views:
    1,119
    Eric Walstad
    Nov 4, 2004
  4. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    1,120
    Michael Sparks
    Jul 30, 2005
  5. Amir  Michail

    cgi relay for python cgi script

    Amir Michail, Oct 4, 2005, in forum: Python
    Replies:
    7
    Views:
    765
    Michael Ekstrand
    Oct 4, 2005
  6. Alfred Z. Newmane

    Re: [OT] Re: "use CGI " hangs "CGI time out "

    Alfred Z. Newmane, Jun 23, 2005, in forum: C Programming
    Replies:
    13
    Views:
    860
    Stan R.
    Jun 24, 2005
  7. epsilon
    Replies:
    4
    Views:
    493
    Gabriel Genellina
    Aug 22, 2007
  8. seven.reeds
    Replies:
    2
    Views:
    194
    seven.reeds
    Jun 21, 2006
Loading...