trouble including multiple variables into send mail script

I have a script that I use to automate the sending of an email (every 91 seconds) to a a comma delimited list of people. The CSV contains their email and name. That works fine, but now I’d like to add their company name and I can’t seem to figure out how to populate the second value Either NAME or COMPANY populate, but never both. Thanks for any pointers.

property secsBetweenMails : 91
property csvHasHeaders : true
property mailSubject : "Welcome back "
property mailBody : "Hi %NAME%,

We were discussing a new widget system for %COMPANY% years ago. Would you like to buy some widgets today? If so, give me a call.

John
(201) 555 1212"

set theAccount to “John @ G Mail”

set csvData to “FirstName,Email,Company
John2,john@mailinator.com,ACME
John3,john2@mailinator.com,Facebook”

set theDropbox to “emailtosalesforce@aefafae.salesforce.com>”

set countSent to 0

– Parse .csv files with Applescript
– Adapted from : http://macscripter.net/viewtopic.php?id=19676
set csvEntries to paragraphs of csvData
if csvHasHeaders then
set startAt to 3
else
set startAt to 2
end if
repeat with i from startAt to count csvEntries
set {theName, theEmail, theCompany} to parseCsvEntry(csvEntries’s item i)

set theBody to replaceName(mailBody, theName) & replaceName(mailBody, theCompany)
tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:mailSubject, content:theBody, visible:true}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:theEmail}
		make new bcc recipient at end of bcc recipients with properties {address:theDropbox}
		send
		set countSent to countSent + 1
		
	end tell
end tell
delay secsBetweenMails

end repeat
display dialog (countSent & “mails sent.”)

to parseCsvEntry(csvEntry)
set AppleScript’s text item delimiters to “,”
set {theName, theEmail, theCompany} to csvEntry’s text items
set AppleScript’s text item delimiters to {“”}
return {theName, theEmail, theCompany}
end parseCsvEntry

to replaceCompany(aBody, aCompany)
set AppleScript’s text item delimiters to “%Company%” & “%Name%”
set parts to aBody’s text items
set newBody to item 1 of parts & aCompany & item 2 of parts & aCompany & item 3 of parts
set AppleScript’s text item delimiters to “”
return newBody
end replaceCompany

to replaceName(aBody, aName)
set AppleScript’s text item delimiters to “%Name%”
set parts to aBody’s text items
set newBody to item 1 of parts & aName & item 2 of parts
set AppleScript’s text item delimiters to “”
return newBody
end replaceName

try with this one :

property secsBetweenMails : 91
property csvHasHeaders : true
property mailSubject : "Welcome back "
property mailBody : "Hi %NAME%,

We were discussing a new widget system for %COMPANY% years ago. Would you like to buy some widgets today? If so, give me a call.

John 
(201) 555 1212"

set theAccount to "John @ G Mail"

set csvData to "FirstName,Email,Company
John2,john@mailinator.com,ACME
John3,john2@mailinator.com,Facebook"

set theDropbox to "emailtosalesforce@aefafae.salesforce.com>"

set countSent to 0

-- Parse .csv files with Applescript
-- Adapted from : http://macscripter.net/viewtopic.php?id=19676
set csvEntries to paragraphs of csvData
if csvHasHeaders then
	set startAt to 2 --3
else
	set startAt to 1 --2
end if

repeat with i from startAt to count csvEntries
	set {theName, theEmail, theCompany} to parseCsvEntry(csvEntries's item i)
	
	set theBody to replace(mailBody, "%NAME%", theName)
	set theBody to replace(theBody, "%COMPANY%", theCompany)
	
	tell application "Mail"
		set theNewMessage to make new outgoing message with properties {subject:mailSubject, content:theBody, visible:true}
		tell theNewMessage
			make new to recipient at end of to recipients with properties {address:theEmail}
			make new bcc recipient at end of bcc recipients with properties {address:theDropbox}
			send
			
		end tell
	end tell
	
	set countSent to countSent + 1
	delay secsBetweenMails
end repeat
display dialog ((countSent as text) & "mails sent.")

to parseCsvEntry(csvEntry)
	set AppleScript's text item delimiters to ","
	set {theName, theEmail, theCompany} to csvEntry's text items
	set AppleScript's text item delimiters to {""}
	return {theName, theEmail, theCompany}
end parseCsvEntry

to replace(aBody, aKey, aValue)
	set AppleScript's text item delimiters to aKey
	set parts to aBody's text items
	log parts
	set AppleScript's text item delimiters to aValue
	set newBody to parts as text
	set AppleScript's text item delimiters to ""
	return newBody
end replace


Yvan KOENIG (VALLAURIS, France) vendredi 9 mai 2014 21:28:42

BINGO! Thanks, Yvan. Enjoy your weekend.

John