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. Advertising

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. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,252
    Jürgen Exner
    Jul 31, 2003
  2. Shailan
    Replies:
    2
    Views:
    899
    Shailan
    Dec 15, 2003
  3. John Smith
    Replies:
    0
    Views:
    3,013
    John Smith
    May 15, 2006
  4. Robert Brewer

    RE: Newbie CGI confusion...

    Robert Brewer, Feb 19, 2004, in forum: Python
    Replies:
    0
    Views:
    429
    Robert Brewer
    Feb 19, 2004
  5. seven.reeds
    Replies:
    2
    Views:
    121
    seven.reeds
    Jun 21, 2006
Loading...

Share This Page