MACSCRPT Archives

June 2010

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mark Lively <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Wed, 2 Jun 2010 12:04:10 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (72 lines)
On Jun 2, 2010, at 11:42 AM, Bill Steele wrote:

> I have a Filemaker script that includes an Applescript to send mail to an address in a field of a record. Used by several people, most of whom use Apple Mail, but there are some oddballs using Thunderbird or old Eudora.
> 
> I know I can use the Filemaker "Send Mail" to utilize the user's default mail client, or  code for a new message via Applescript with
> 
> set mailto to "mailto:" & eAddress
> open location mailto
> 
> Is there a generic way to add an attachment?
> 
> Bill Steele
> [log in to unmask]
> 
Filemaker 11 I think has built in mail.  If that isn't an option there is sendmail.

I use this script to take a screenshot and email it.  Swapping in your file should be fairly simple.

-- Body Content
	set theData to "ZOMG Fire!!!11!!ONE!!"

-- Target email(s)
	set targetAddress to "[log in to unmask]"

--Name of the file you are sending.  I generate a date in it
	set fileName to do shell script "date +SCHDEDULER_%y%m%d_%H%M.png"

--Path to a temp file
	set filename2 to "/tmp/" & fileName & ".tmp"

--set up Mail Headers
	do shell script "date +'Date: %a %b %e %Y %H:%M:%S %z'>" & filename2
	do shell script "echo 'Subject: SCHDEDULER Screen Shot'>>" & filename2
	do shell script "echo 'To: " & targetAddress & "'>>" & filename2
	do shell script "echo 'From: SCHDEDULER'>>" & filename2
	do shell script "echo 'Mime-Version: 1.0'>>" & filename2

--You should probably change the boundary to something else
	do shell script "echo 'Content-type: multipart/mixes; boundary=AccuBoundary_ConstantSep'>>" & filename2
	do shell script "echo >>" & filename2

--Set up the body of the email
	do shell script "echo '--AccuBoundary_ConstantSep'>>" & filename2
	do shell script "echo 'Content-type: text/plain;format=flowed'>>" & filename2
	do shell script "echo 'Content-transfer-encoding: 7bit'>>" & filename2

--Now the body
	do shell script "echo " & quoted form of theData & ">>" & filename2
	do shell script "echo >>" & filename2

--The attachment
	do shell script "echo '--AccuBoundary_ConstantSep'>>" & filename2
	do shell script "echo 'Content-type: application/octet-stream; name=" & fileName & "'>>" & filename2
	do shell script "echo 'Content-transfer-encoding: BASE64'>>" & filename2
	do shell script "echo 'Content-Disposition: Attachment; filename=" & fileName & "'>>" & filename2
	do shell script "echo >>" & filename2

--The next line gets dropped if you already have a file in place
	do shell script "screencapture /tmp/" & fileName

--UUencode the attachment to send and strip headers.
	do shell script "uuencode -m /tmp/" & fileName & " " & fileName & "| grep -v " & fileName & " >>" & filename2

--Send it
	do shell script "sendmail " & targetAddress & " <" & filename2

--Clean up
	do shell script "rm /tmp/" & fileName & " " & filename2

-Mark
Remembers back in the day when the world was more trusting.

ATOM RSS1 RSS2