sending text via e-mail

My code will simply not work. What happens is you enter text into a text window called “text” and then you click the ''send now" button to send it as an e-mail, but very time It sets the text in the window to the body of the message it says the variable textnote is not defined, here is the code.
tell window of theObject
try
set textnote to contents of text field “text” as text
end try
end tell
repeat
set theResult to display dialog “To whom would you like to send this message?” default answer “Example: Jane Doe”
set theName to text returned of theResult
if (theName does not start with “Example:”) then
exit repeat
end if
end repeat

-- Repeat this loop until the text entered has been changed from the default example text.
-- Email address validation could be done at this point.
repeat
	set theResult to display dialog "What is their email address?" default answer "Example: janedoe@example.com"
	set theAddress to text returned of theResult
	if (theAddress does not start with "Example:") then
		exit repeat
	end if
end repeat

-- Prompt for message subject
set theResult to display dialog "What would you like the subject of the message to be?" default answer "I'm sending this via AppleScript!"
set theSubject to text returned of theResult

-- Prompt for whether an attachment is desired. If so, prompt for the location of the file.
set theResult to display dialog "Would you like to attach some files to this message?" buttons {"Yes", "No"} default button 1
set wantsAttachment to button returned of theResult
if wantsAttachment is equal to "Yes" then
	set theAttachment to choose file
end if

-- Prompt for message body
set theResult to display dialog "What would you like to say in the body of the message?" default answer textnote
set theBody to text returned of theResult

-- Display a list of all the user's defined signatures. Skip if no signatures are defined.
tell application "Mail" to set everySignature to name of every signature
set theSignature to ""
if (count of everySignature) is greater than 0 then
	set everySignature to {"None"} & everySignature
	set theResult to choose from list everySignature with prompt ¬
		"Select a signature to use with this message:" default items {"None"} without multiple selections allowed
	if theResult is not equal to false then
		tell application "Mail" to set theSignature to signature (item 1 of theResult)
	end if
end if

-- Go through each account and constuct a list of possible addresses
-- to use as a return address for this message.
tell application "Mail"
	set listOfSenders to {}
	set everyAccount to every account
	repeat with eachAccount in everyAccount
		set everyEmailAddress to email addresses of eachAccount
		if (everyEmailAddress is not equal to missing value) then
			repeat with eachEmailAddress in everyEmailAddress
				set listOfSenders to listOfSenders & {(full name of eachAccount & " <" & eachEmailAddress & ">") as string}
			end repeat
		end if
	end repeat
end tell

-- Prompt the user to select which account to send this message from.
set theResult to choose from list listOfSenders with prompt ¬
	"Which account would you like to send this message from?" without multiple selections allowed
if theResult is not equal to false then
	set theSender to item 1 of theResult
	tell application "Mail"
		-- Properties can be specified in a record when creating the message or
		-- afterwards by setting individual property values.
		set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
		tell newMessage
			-- Default is false. Determines whether the compose window will
			-- show on the screen or whether it will happen in the background.
			set visible to true
			set sender to theSender
			make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
			tell content
				if (wantsAttachment is equal to "Yes") then
					-- Position must be specified for attachments
					make new attachment with properties {file name:theAttachment} at before the last paragraph
				end if
			end tell
			if (theSignature is not equal to "") then
				set message signature to theSignature
			end if
		end tell
		-- Bring the new compose window to the foreground, in all its glory
		activate
	end tell
end if

end choose menu item

http://home.comcast.net/~themacgeek/0/files/iCalMail13.zip
It’s my app, it’s open, and it works (for sending email thru mail)
take a look

That might help, but I do not want to use your code, as I may produce this app commercially. Thanks, Though!

You should set your variable as a global so that it persists after the first tell statement.

Prepend your script with:

global textnote

That should do the trick.

Thanks, but it says after I place it in: “A variable cannot be lacally and globally defined”, why is that? I think you have it right in saying I should put up global textnote, but my script refuses to work.