[ANSWERED]Send Email Using Variable Content as Address

Posted on
Mon Jul 28, 2014 2:55 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

[ANSWERED]Send Email Using Variable Content as Address

Hey,

I have a script I've been using to capture a webcam image and mail it to the address contained in a variable.
Works great in 10.5.8 but errors out using 10.8.

The format, I believe the script wants for the sender is {"test@test.com"}
I used the ASCII code for the " symbol in the address as I couldn't use a " directly in the applescript.

This code works fine in 10.5.8

Code: Select all
tell application "SecuritySpy"
   capture image camera number 0 as "/Users/JD/Pictures/ss/0.jpg" with overwrite
end tell

tell application "IndigoServer"
   set theInsert to "This attached image was taken at " & value of variable "ClockTimeAmPm" & " with your front camera." & return & return & "Have a terrific " & value of variable "TimeOfDayShort" & "!"
   set PrintDateTimeName to value of variable "DayDate"
   set the_mailto to "{" & (ASCII character 34) & value of variable "CamMailAddress" & (ASCII character 34) & "}"
   --set the value of variable "CamMailAddressTest" to the_mailto
end tell

set theSenderTemp to "info@whitefishxxxxxxx.com"

set nameList to {"Customer"}

set TheName to "Front Webcam"

set the_subject to "Alert! Motion Detected From Front Camera."
set the_content to ("Hey," & return & return & "This is an automated message from your Indigo Security System." & return & return & theInsert & return & return & "To report a problem with your system contact " & theSenderTemp & "." & return & return & "Your image from, " & TheName as text) & ", from the folder " & PrintDateTimeName & " has been backed up into the folder Security Cameras." & return & return

tell application "Mail"
   activate
   set attachmentVar to "/Users/JD/Pictures/ss/1.jpg"
   set newMessage to make new outgoing message with properties {address:the_mailto, subject:the_subject, content:the_content}
   tell newMessage
      set x to offset of "Indigo Security System." in the_content
      repeat with y from 0 to count of "Indigo Security System."
         set font of character (x + y) of content to "Helvetica Bold"
         set color of character (x + y) of content to {48632, 1630, 1102}
      end repeat
      set x to offset of TheName in the_content
      repeat with y from 0 to count of TheName
         set font of character (x + y) of content to "Helvetica Bold"
      end repeat
      set x to offset of PrintDateTimeName in the_content
      repeat with y from 0 to count of PrintDateTimeName
         set font of character (x + y) of content to "Helvetica Bold"
      end repeat
      set x to offset of "Security Cameras." in the_content
      repeat with y from 0 to count of "Security Cameras."
         set font of character (x + y) of content to "Helvetica Bold"
         set size of content to (17)
      end repeat
      make new attachment with properties {file name:attachmentVar}
      repeat with i from 1 to count nameList
         make new to recipient at end of to recipients with properties {name:item i of nameList, address:item i of the_mailto}
      end repeat
      
      send
   end tell
end tell


Here are a couple images of the error in 10.8

Any help greatly appreciated!

Thanks,

Carl

Image

Image

Posted on
Mon Jul 28, 2014 5:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Send Email Using Variable Content as Address

Something about the Mail app has apparently changed since it's the app that's complaining when you compile. Not sure what changed though.

Maybe just store the Indigo variable value itself in the_mailto then set address: {the_mailto} in the properties of the actual mail message and see if that works.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Jul 28, 2014 5:45 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Send Email Using Variable Content as Address

Kinda doubt it's the address it's complaining about. I revised the script to:
set the_mailto to {"email@email.com"}
and get the same error.

This script works fine on 10.8

Code: Select all
tell application "Mail"
   set addressList to {"ckeyes@cxxxxx.net"}
   set nameList to {"Carl"}
   set bodyvar to "Motion was detected in your driveway. Here's an image of what was there."
   set subjectvar to "Driveway Security Camera Image"
   set attachmentVar to "/Users/JD/Pictures/ss/0.jpg"
   set newMessage to (a reference to (make new outgoing message))
   tell newMessage
      repeat with i from 1 to count nameList
         make new to recipient at end of to recipients with properties {name:item i of nameList, address:item i of addressList}
      end repeat
      set the subject to subjectvar
      set the content to bodyvar
      tell content
         make new attachment with properties {file name:attachmentVar}
      end tell
   end tell
   send newMessage
end tell


Quite the mystery.

Thanks a bunch,

Carl

Posted on
Mon Jul 28, 2014 8:00 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Send Email Using Variable Content as Address

Carl:

Pulling up the AppleScript dictionary for a message, there is no "address" property defined -- I suspect that was the change you are seeing. There is a recipient with address and name properties. I think the solution is to take your original code, but do not pass the "address" in the first property dictionary; pass in the subject and content, then add the address:

Code: Select all
set newMessage to make new outgoing message with properties {subject:the_subject, content:the_content}
make new to recipient at end of to recipients with properties  {name:"Carl", address:the_mailto}

(Note: untested, just based off the dictionaries, that is what I would try...)

Adam

Posted on
Mon Jul 28, 2014 8:38 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Send Email Using Variable Content as Address

Tried inserting your code but get this error.

Many thanks for checking it out!

Carl
Attachments
email error.jpg
email error.jpg (112.19 KiB) Viewed 3509 times

Posted on
Mon Jul 28, 2014 9:29 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Send Email Using Variable Content as Address

My fault, Carl, re-looked over your script and I think your the_mailto has curly brackets and double quotes in the string, if I am reading it correctly... give it a try with a hardcoded email address instead of the_mailto variable and, if that works, ensure the_mailto is just the email address. (set the_mailto to value of variable "CamMailAddress")

Adam

Posted on
Mon Jul 28, 2014 11:13 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Send Email Using Variable Content as Address

Thanks a bunch Adam. Works perfectly!

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests