Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. set people2Send to {} -- start off with an empty list
  2.  
  3. --set the path to your plain text file with addresses, and name, tab delimited
  4. --change the username
  5.  
  6. set everybody to read file ("Macintosh HD:Users:sjardim:people_to_send.txt")
  7. --set the path to the pdf files. The TXT file MUST be saved in Mac OS Roman encoding
  8. set rootPath to "/Users/sjardim/pdf/"
  9.  
  10. set pcount to count paragraphs in everybody
  11. repeat with i from 1 to number of paragraphs in everybody
  12. set this_item to paragraph i of everybody
  13.  
  14. set thisName to "" -- set to blank
  15. -- 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
  16. -- instead of stopping. The Name_text will reamin as "" if it does
  17. try
  18. --use delimiters (tab) in this case to split the result of this_item and try to set Name_text to the name
  19. set AppleScript's text item delimiters to tab
  20. set para_text to text of this_item
  21. --get the second half of paragraph
  22. set thisName to text item 1 of para_text
  23. end try
  24. --get the first half of paragraph
  25. set emailAddress to text item 2 of para_text
  26. set thisFile to rootPath & text item 3 of para_text & ".pdf"
  27. log thisFile
  28.  
  29. set emailCcAddress to text item 4 of para_text
  30. set emailCcAddress2 to text item 5 of para_text
  31. log thisFile
  32.  
  33. set ccAddressesList to {} -- new list to contain multiple cc address
  34. copy emailCcAddress to the end of the ccAddressesList
  35. copy emailCcAddress2 to the end of the ccAddressesList
  36. -- return ccAddressesList -- return in the console
  37.  
  38. -- Check if there is at least one CC adress
  39. if emailCcAddress as string is not equal to "" then
  40. copy {_name:thisName, _address:emailAddress, _Ccaddress:emailCcAddress, _file:thisFile} to end of people2Send
  41. else
  42. copy {_name:thisName, _address:emailAddress, _Ccaddress:"", _file:thisFile} to end of people2Send
  43. end if
  44.  
  45. --reset the delimiters
  46. set AppleScript's text item delimiters to ""
  47.  
  48. end repeat
  49.  
  50. tell application "Microsoft Outlook"
  51. repeat with eachPerson in people2Send -- now loop through the names/addresses from above
  52. set theAccount to (second exchange account)
  53. set msgSubject to "Your Workshop Certificate"
  54. set fromPerson to "<strong>John Smith</strong>"
  55. set msgBody to "Dear " & (_name of eachPerson) & "," & "<br>" & "Thank you for attending our workshop. Please find enclosed your certificate of attendance as a PDF attachment." & "<br>" & "We thank you for taking part in this training initiative." & "<br><br>" & "Best regards," & "<br>" & fromPerson -- here's where you craft the message text
  56. set newMsg to (make new outgoing message with properties {account:theAccount, subject:msgSubject, content:msgBody}) -- create the message
  57. tell newMsg
  58. make new recipient at end of to recipients with properties {email address:{name:eachPerson's _name, address:eachPerson's _address}} -- add the recipient
  59.  
  60. repeat with address in ccAddressesList
  61. if eachPerson's _Ccaddress as string is not equal to "" then
  62. make new recipient at end of cc recipients with properties {email address:{address:address}} -- add the recipient
  63. end if
  64. end repeat
  65. make new attachment with properties {file:eachPerson's _file} -- add an attachment
  66. end tell
  67. open newMsg -- and just open it
  68. -- send newMsg -- and send it on its way
  69. end repeat
  70. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement