Hi Everyone! I wrote this script last night so that I never have to remember to wish someone happy birthday again-- I put a call to this script in my crontab so it autostarts every day.
I am just wondering, does anyone here see any improvements that can be made? I don’t know much about email and headers, but I wonder since this is being emailed from localhost and I don’t specify mimetypes, etc if these emails generated are subject to be interpreted as spam… So I am curious if anyone has any feedback?
Here’s the script…
set m to month of (current date)
set d to day of (current date)
tell application "Address Book" to tell people
repeat with thisPerson in it
try
set thebirthday to thisPerson's birth date as date
set ab_m to month of thebirthday
set ab_d to day of thebirthday
set logemails to ""
set currentcount to 0
if ab_m = m and ab_d = d then
set thename to thisPerson's name
set thefirstname to thisPerson's first name
set theEmails to thisPerson's email's value
set thecount to count (theEmails)
repeat with currentemail in theEmails
set currentcount to currentcount + 1
set logemails to logemails & currentemail
if currentcount < thecount then
set logemails to logemails & ", "
end if
set birthdayfile to ".birthdayemail.txt"
set birthdaylog to ".bdaylog.txt"
set birthdaygreeting to "Subject: From Patrick.. Happy Birthday " & thename & "!!!
From: Patrick <myemail@myemail.com>
To: " & thename & " <" & currentemail & ">
Happy birthday to you!
Happy birthday to you!
Happy birthday dear " & thefirstname & "...
Happy birthday to you!!!!
... and many more!
I just wanted to write you and say happy birthday!!!
-p"
set filelocation to my createemail(birthdayfile, birthdaygreeting)
do shell script "sendmail -bm " & currentemail & " < " & filelocation
do shell script "rm " & filelocation
end repeat
set myinfo to "Subject: Birthday Email sent to " & thename & "
Birthday wishes were sent to...
" & logemails
set filelocation to my createemail(birthdaylog, myinfo)
do shell script "sendmail -bm myemail@myemail.com < " & filelocation
do shell script "rm " & filelocation
end if
end try
end repeat
end tell
on createemail(the_filename, the_list)
set docFolder to (path to desktop as string)
set docName to docFolder & the_filename as list
set docunix to POSIX path of docFolder & the_filename
set docPointer to (open for access docName with write permission)
set eof of docPointer to 0
write the_list to docPointer as string
close access docPointer
return docunix
end createemail