473,666 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing string from one file to another

Kun
I have a python-cgi form whose sole purpose is to email.

It has the fields 'to', 'from', 'subject', 'body', etc. and if the user
fills them out and clicks submit, it will invoke another file called
mail.py which uses smtplib to send the message.

This works fine but instead of typing in a 'body', i would like the
initial python program to just send a string as the body of the email.
now normally i'd just set the msg in the mail.py file equal to the
string, however, i do not know how to link a string from another python
file to the mail.py file.

does anyone know a solution to this?
Apr 17 '06 #1
7 2755
Kun
Kun wrote:
I have a python-cgi form whose sole purpose is to email.

It has the fields 'to', 'from', 'subject', 'body', etc. and if the user
fills them out and clicks submit, it will invoke another file called
mail.py which uses smtplib to send the message.

This works fine but instead of typing in a 'body', i would like the
initial python program to just send a string as the body of the email.
now normally i'd just set the msg in the mail.py file equal to the
string, however, i do not know how to link a string from another python
file to the mail.py file.

does anyone know a solution to this?


i am aware that i could write the string to a text file and invoke it
with the second python program, however, unfortunately i do not have
write permission on the server i am working with, thus we need to find
some other way...

your help would be greatly appreciated
Apr 17 '06 #2
I V
Kun wrote:
This works fine but instead of typing in a 'body', i would like the
initial python program to just send a string as the body of the email.
now normally i'd just set the msg in the mail.py file equal to the
string, however, i do not know how to link a string from another python
file to the mail.py file.


Where does mail.py get the body from at the moment? And how are you
invoking mail.py? The obvious would be to import mail.py and call a
function in it; then, you would just need to change the string you pass
to the function. But presumably that's not how you've got it set up or
you wouldn't be asking the question. If you can explain a bit more how
your program works that would be helpful, maybe post an exerpt of the
code that shows where mail.py gets invoked from the main program, and
the bit of mail.py that accesses the body that gets sent.

Apr 17 '06 #3
Kun
I V wrote:
Kun wrote:
This works fine but instead of typing in a 'body', i would like the
initial python program to just send a string as the body of the email.
now normally i'd just set the msg in the mail.py file equal to the
string, however, i do not know how to link a string from another python
file to the mail.py file.


Where does mail.py get the body from at the moment? And how are you
invoking mail.py? The obvious would be to import mail.py and call a
function in it; then, you would just need to change the string you pass
to the function. But presumably that's not how you've got it set up or
you wouldn't be asking the question. If you can explain a bit more how
your program works that would be helpful, maybe post an exerpt of the
code that shows where mail.py gets invoked from the main program, and
the bit of mail.py that accesses the body that gets sent.

mail currently gets the body from an input box.

this is where mail.py gets invoked:

<h1>Email Results</h1>
<p>
<Table>
<FORM METHOD="post" ACTION="mail.py ">

<TR><TD>SMTP Server:</TD>
<TD><input type="text" name="SMTP Server"
value="webmail. wharton.upenn.e du" size=20>
</TD></TR>
<TR><TD>Usernam e:</TD>
<TD><input type="text" name="Username" size=20>
</TD></TR>
<TR><TD>Passwor d:</TD>
<TD><input type="password" name="Password" size=20>
</TD></TR>
<TR><TD>From: </TD>
<TD><input type="text" name="From" size=20>
</TD></TR>
<TR><TD>To:</TD>
<TD><input type="text" name="To" size=20>
</TD></TR>
<TR><TD>Subject :</TD>
<TD><input type="text" name="Subject" size=20>
</TD></TR>
<TR><TD>Message :</TD>
<TD><TEXTAREA wrap="virtual" name="Message" cols=40 rows=5>
</TEXTAREA></TD></TR>
<TR><TD></TD><TD><input type="submit" value="Submit"> <input type="reset">
</form></TD></TR></Table></HTML>"""


this is mail.py


#!/usr/bin/env python
import cgi
import smtplib
import os
import sys
import urllib
import re
from email.MIMEText import MIMEText

print "Content-type: text/html\n"

form = cgi.FieldStorag e() #Initializes the form dictionary to take data
from html form
key = [ 'SMTP Server', 'Username', 'Password', 'From', 'To', 'Subject',
'Message' ]

def get(form, key):
if form.has_key(ke y):
return form[key].value
else:
return ""

if get(form, "SMTP Server") or get(form, "Username") or get(form,
"Password") or get(form, "From") or get(form, "To") or get(form,
"Subject") or get(form, "Message"):
print ''
else:
print 'Error: You did not enter any Email parameters'
print '<br>'
print '<a
raise ValueError("not hing entered")
##mail = open('mail.txt' ,'rb')
##msg = MIMEText(mail.r ead())
##mail.close()
msg = MIMEText(form['Message'].value) #mime text is a method that takes
in a text variable and creates a dictionary whose contects are
inatialized according to the text.
##print MIMEText(form['Message'].value)
##msg = msg.as_string() + mail

msg['Subject'] = form['Subject'].value
msg['From'] = form['From'].value
msg['To'] = form['To'].value

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP(fo rm['SMTP Server'].value)
s.login(form['Username'].value,form['Password'].value)
s.sendmail(form['From'].value, [form['To'].value], msg.as_string() )
s.close()

print """<HTML><Head> <Title>Email Confirmation
Page</Title></Head><br><Body> Your email has been sent.<br></Body></HTML>"""
Apr 17 '06 #4
I V
Kun wrote:
mail currently gets the body from an input box.

this is where mail.py gets invoked:


OK, I'm a bit confused. Where is the "initial python program" in all
this? You seem to have an one python program (mail.py) and an HTML
form. As it stands, I don't see why you can't change mail.py so that it
refers to your string instead of msg.as_string() .

Apr 17 '06 #5
Kun
I V wrote:
Kun wrote:
mail currently gets the body from an input box.

this is where mail.py gets invoked:


OK, I'm a bit confused. Where is the "initial python program" in all
this? You seem to have an one python program (mail.py) and an HTML
form. As it stands, I don't see why you can't change mail.py so that it
refers to your string instead of msg.as_string() .

the html i pasted is part of a python-cgi file that is the 'initial'
file. i can't just tell mail.py to use the string because the string is
defined in the first python profile, not mail.py.
Apr 17 '06 #6
Ant
I assume that you are trying to pass data from one 'standalone' cgi
script to another cgi script (mail.py). Depending on what exactly you
are trying to do, you could either set the information in a cookie, or
simply have a hidden input (<input type='hidden' name="data_to_p ass_on"
value="bob">) element in the HTML which gets populated by the initial
cgi script and is then read by mail.py.

Apr 17 '06 #7
In article <e1***********@ netnews.upenn.e du>, Kun <ne*******@gmai l.com>
wrote:
I have a python-cgi form whose sole purpose is to email.

It has the fields 'to', 'from', 'subject', 'body', etc. and if the user
fills them out and clicks submit, it will invoke another file called
mail.py which uses smtplib to send the message.


Why do you need 2 Python scripts? Why can't the first one use smtplib to
send the message directly?
Apr 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14929
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
58
10122
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
6
4276
by: csvka | last post by:
Hello, I wonder if I could pick your brains. I'm beginning to learn about C++. I have opened a file in my program and I want to read lines from it. I would like this to be done in a separate function called readline() because I would also like to do some processing on the line each time (ignoring comments and so on). I have:
7
4742
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
19
2521
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet GetCategories() { SqlConnection conn = new SqlConnection("Data Source=DEVSERVER;Initial Catalog=XXXX;User ID=X;Password=Y");
5
8612
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
0
1539
by: Iain McIntosh | last post by:
Hello if anyone can help me with this I will be very grateful. I have a working version of this program as a windows application, when I try to port it over to c# ASP.NET I can't make it work. The program works in the following way. Uploads a file to the server. (works) Populates a dataset (works) Passing the dataset to another class (doesn't work)
7
1729
by: =?Utf-8?B?YmVyaWNr?= | last post by:
New to this, I used to pass an array like this function BytesToString(byref myarray() as byte, somethingelse as long) as long and m = BytesToString(fooBar(), bluenose) This would send the descriptor or pointer to the array to the function
13
3195
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the functions that require a structure to be passed to them. The function declaration in the .h file is of the form: SDCERR GetConfig(char *name, SDCConfig *cfg); where SDCConfig is a structure defined in the .h file. I am not much of a C (or C#)...
2
1781
by: 1qaz2wsx | last post by:
Hello reader, On my site i pass variables from one page to another, this is no problem. But when i'll get a string with a + or & sign for example this NE SO 1.1 + 1.2 string I will lose the + sign when I'll pass it from one page to another. I will get NE SO 1.1 1.2 this result when I'll pass it from one page to another. Even if I do this with the following simple code I will get the same result: FILE : SENDING.ASP <% name2 = "NE SO...
0
8448
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.