Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
Hey guys,

I found this script below. Basically it reads from two sourse files. One has some info that you want to put into the body of an email. The other has the email addresses you want to send the message to. It reads both of them and then sends out the e-mail using the mail application. I have used it on different machines before.

But the one I'm trying it on now not only inserts the info it should, but it is insertion all the character info of the file itself: color scheme numbers, charcter sizes, etc. Why would it do that, and how could I fix it?

Code:
	--direct to your plain text file with addresses, and name, tab delimited
	set sourceFile to open for access "MacintoshHD:Users:test:Movies:address.txt"
	set theAddressDOC to read sourceFile
	close access sourceFile
	
	set pcount to count paragraphs in theAddressDOC
	repeat with i from 1 to number of paragraphs in theAddressDOC
		set this_item to paragraph i of theAddressDOC
		
		set Name_text to "" -- set to blank
		-- using try so if there is a an error, in this case it will be when the is no name, the script will carry on
		-- instead of stopping. The Name_text will reamin as "" if it does
		try
			--use delimiters (tab) in this case to split the result of this_item and try to set Name_text to the name
			set AppleScript's text item delimiters to tab
			set para_text to text of this_item
			--get the second half of paragraph
			set Name_text to text item 2 of para_text
		end try
		--get the first half of paragraph
		set address_text to text item 1 of para_text
		
		--reset the delimiters
		set AppleScript's text item delimiters to ""
		
		set theAddress to address_text
		
		-- direct to a doc of what you want the email to say in plain text
		set sourceFile to open for access "MacintoshHD:Users:test:Movies:web links body text.txt"
		set theletter to read sourceFile
		close access sourceFile
		
		-- What is the subject of the Emails
		set theSubject to "Here Are Your Requested Uploaded Links"
		
		-- Check to see if Name_text contains a name or not
		if Name_text is "" then
			--if no name
			set theBody to " you to view" & theletter
			
		else
			--the must be a name
			set theBody to "Here are the links for " & Name_text & theletter
		end if
		theBody
		
		
		-- Choose the account to send the message from
		set theSender to "myaccount@gmail.com"
		
		tell application "Mail"
			
			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 {address:theAddress}
				tell content
					tell application "Mail"
						send newMessage
					end tell
					-- delay to allow the Mail program to send and not bog down, adjust as needed
					delay 10
				end tell
			end tell
		end tell
		
	end repeat
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.