473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Sending part of a page as the body of an email

Kun
I currently have a python-cgi script that extracts data from a mysql
table. I would like to save this data as a string and send it to a
recipient via email.

I know how to send email using the smtp lib, but what I do not know his
how to save a portion of the page as a string. Any pointers?
Apr 16 '06 #1
1 1082
Kun wrote:
I currently have a python-cgi script that extracts data from a mysql
table. I would like to save this data as a string and send it to a
recipient via email.

I know how to send email using the smtp lib, but what I do not know his
how to save a portion of the page as a string. Any pointers?


#At the top of your CGI script import these
import sys
import StringIO

#Create a StringIO object to hold output
string_io = StringIO.StringIO()
#Save the old sys.stdout so we can go back to it later
old_stdout = sys.stdout

#Normal output goes here

#To start capturing output replace sys.stdout with the StringIO object
sys.stdout = string_io

#Captured output goes here

#To finish capturing
sys.stdout = old_stdout

#To get the captured text from the StringIO object do:
captured_text = string_io.getvalue()

#To output the captured text to the original sys.stdout
#If this is omitted, the captured_text will not be sent to the browser
old_stdout.write(captured_text)

#You can repeat this capturing section several times and the output
#will accumulate in the StringIO object. To clear the contents of the
#StringIO object between sections do:
#string_io.truncate(0)

#More normal output goes here
#Do whatever you want with captured_text here...
#When finished with string_io, close it to free up the memory buffers
string_io.close()
--
Jesse Hager
email = "wr********@tznvy.pbz".decode("rot13")
Apr 16 '06 #2

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

Similar topics

5
by: BaWork | last post by:
I have a web form where a client can select which site members to send an email to. This form is populated from the contents of the member table, so the form can have 0-x names listed on it...
2
by: Joe | last post by:
Hi, I am sending an email from an asp page. Besides sending an email to sender, I am sending myself a BCC also. Out of 100 emails sent, about 5 recipients received a blank email (no text in...
1
by: festivalman | last post by:
Hi, sorry if this is in the wrong spot. Finding the newsgroups on MS's site could have been easier Here's my problem I've got some old asp's that are running our simple web site. In a section,...
6
by: Eduardo Rosa | last post by:
Somebody knows how I queue email using .Net? thanks a lot
4
by: splicemix | last post by:
Hi all, I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost to send emails, and prevents access to php.ini, so I spent some time...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
4
by: Roger Withnell | last post by:
I'm sending Russian text in an email generated from the website which displays in the email as ?????????? The website is set to codepage 65001 and the charset to utf-8. Please advise. ...
3
by: chaitanya02 | last post by:
Hi All,, I used this code to send an email to anyone, from my asp page, which accepts email address from the users of the form: Sending a text e-mail using a remote server: <% Set...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
8
by: Marty | last post by:
I'm having issues sending an email to an "@page.nextel.com" email address. I can send to any other email address fine, but when I try the page.nextel.com it gives me this error: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.