The applescript below is supposed to send out an email. When I run the script everything appears fine. The recipients address, subject line, and e-mail body all go to the right places. But when it goes to send the e-mail out, I get the following error:
Recipient’s e-mail address appears to not exist.
I checked for miss spellings, but there were none. However, if I delete the email address and simply re-write it, Mail will send it out no problem. My only thought is that something may be going on with the reference file. The script pulls the email address from a plain text document reference file that is create after the user inserts their address as you will see below. Any ideas as to where my error is coming from?
set theText to "@yahoo.com"
tell application "Finder"
display dialog "What is your e-mail address?" default answer theText
end tell
set finalResult to text returned of result
set addressFile to "address.txt"
set logName to ((path to movies folder as text) & addressFile)
try
set fileRef to open for access file logName with write permission
write finalResult & return to fileRef starting at eof
close access fileRef
on error
try
close file logName
end try
end try
set theText to "File Name"
tell application "Finder"
display dialog "What is the name of your subject?" default answer theText
end tell
set finalResult to text returned of result
set videoFile to "File Name.txt"
set logName to ((path to movies folder as text) & videoFile)
try
set fileRef to open for access file logName with write permission
write finalResult & return to fileRef starting at eof
close access fileRef
on error
try
close file logName
end try
end try
tell application "Finder"
set theFolder to ((path to movies folder as text) & "myFolder") as alias
set theList to name of (every file in theFolder)
end tell
repeat with i from 1 to (count theList)
set theName to (item i of theList)
set item i of theList to ("http://mywebsite.com/" & theName)
end repeat
set theText to "
"
repeat with i from 1 to (count theList)
set theText to (theText & (item i of theList) & "
")
end repeat
set finalResult to theText
set bodyFile to "Links Body.txt"
set logName to ((path to movies folder as text) & bodyFile)
try
set fileRef to open for access file logName with write permission
write finalResult & return to fileRef starting at eof
close access fileRef
on error
try
close file logName
end try
end try
--direct to your plain text file with addresses, and name, tab delimited
set addressFile to "address.txt"
set sourceFile to open for access ((path to movies folder as text) & addressFile)
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 address_text to this_item
set theAddress to address_text
-- direct to a doc of what you want the email to say in plain text
set bodyFile to "Links Body.txt"
set sourceFile to open for access ((path to movies folder as text) & bodyFile)
set theletter to read sourceFile
close access sourceFile
set subjectFile to "File Name.txt"
set sourceFile to open for access ((path to movies folder as text) & subjectFile)
set theSubject to read sourceFile
close access sourceFile
-- What is the subject of the Emails
set theSubject to "Here is your link:" & theSubject
set theBody to " Your Link is located below:" & theletter
-- 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