Go Back   The macosxhints Forums > OS X Help Requests > Applications



Reply
 
Thread Tools Rate Thread Display Modes
Old 01-14-2004, 06:43 AM   #1
m2uk
Prospect
 
Join Date: Jan 2004
Posts: 5
Scripting to email help (or applet sought!)

Hi there.

(I originally posted this in the Macrumours site but so far noone has been able to assist - just in case someone takes offence at reading this twice!)

I have a horrible job to do in order to "migrate" a system as...

Essentially I need a means to plonk a lot of files in a folder (nothing elaborate) and email them to a pre determined address which at the other end the software we have will automatically file them into the custom app for further processing.

Trouble is, they have to be one attachment (PDF) per email so that rules out me just dragging in a directory worth at a time.

Does anyone know of any solution or a bit of code (I am a non programmer) which would do this. It seems the stuff that Applescript or Folder actions should do, but it a bit late to learn now.

Literally, it needs to be something like.

If files exist in directory, then email the first item to address and then delete given filename, then repeat from beginning until there is nothing else to do.

I have Googled! and done searches here and on many other forums and either I am sticking in entirely the wrong phrases and terms or noone has wanted to do such an odd thing before which I can understand.

I even started looking at webcam picture applets in case someone wanted to email their webcam pictures as a security system to no avail.

Any help, pointers or tips welcomed ! Thanks.
m2uk is offline   Reply With Quote
Old 01-14-2004, 07:41 AM   #2
robJ
Major Leaguer
 
Join Date: Aug 2003
Posts: 429
Which email client are you using to send the files? Which version of Mac OS? Are the files too numerous and/or large to compress and send as one archive (zip, sit, etc.)?

-- Rob
robJ is offline   Reply With Quote
Old 01-14-2004, 07:46 AM   #3
m2uk
Prospect
 
Join Date: Jan 2004
Posts: 5
Ah.. I guess it would help if I gave more information!

10.3.2. OS X client Proposed to use the built in Apple Mail. The application I need to send to can only accept one attachment per email and it must not be archived. File sizes can be up to several megs.

Could be several thousand files by the end of the program (but i would just run it per directory!)

It is going to only one mail address on our internal LAN for some document filing system as a means to get historical data in.

HTH Thanks !
m2uk is offline   Reply With Quote
Old 01-14-2004, 09:09 AM   #4
robJ
Major Leaguer
 
Join Date: Aug 2003
Posts: 429
Well, I gave it a shot but Mail, as usual, is very frustrating to script (for me anyway). I'm still running OS X 10.2.8 and Mail version 1.2.5 and I've heard that Mail's scripting support has improved in Panther.

It's entirely possible to use a folder action for this task but someone else will need to provide the Mail script. Sorry.

-- Rob (a Eudora user)
robJ is offline   Reply With Quote
Old 01-14-2004, 09:12 AM   #5
m2uk
Prospect
 
Join Date: Jan 2004
Posts: 5
Thanks. I do not know anything yet about scripting and whilst it is one thing to learn, there are a few other things ahead of the list so far. Google searches suggest that not many people are exploiting Folder Actions.. or they are not sharing their results so that "folks like me" can avail themselves of their hard programming work !
m2uk is offline   Reply With Quote
Old 01-14-2004, 10:31 AM   #6
robJ
Major Leaguer
 
Join Date: Aug 2003
Posts: 429
Smile This "might" work but no guarantees

Well, I did some poking around at MacScripter's BBS and found some code to create a new message with an attachment. Here's a folder action that might come close to what you need (complete script untested). You need to modify the recipient name and address values in line 10. If you plan to try it, I suggest that you test it on a folder/files that don't matter until you see how it behaves. It should move sent files to the Finder's trash.

Code:
on adding folder items to this_folder after receiving added_items
	set sent_files to {}
	repeat with file_ in added_items
		try
			set file_name to name of (info for file_)
			tell application "Mail"
				set the nm to make new outgoing message with properties {subject:file_name}
				tell the nm
					make new to recipient at end of to recipients with properties ¬
						{name:"Archive Dept.", address:"archives@yourdomain.com"}
					tell content
						make new attachment with properties ¬
							{file name:file_} at before the first character
					end tell
					set visible to true
				end tell
				send nm
			end tell
			copy file_ to end of sent_files
		on error e
			-- do something (generate a log?) if an error occurs during execution
		end try
	end repeat
	tell application "Finder" to delete sent_files
end adding folder items to
-- Rob
robJ is offline   Reply With Quote
Old 01-14-2004, 02:34 PM   #7
jbc
All Star
 
Join Date: Feb 2003
Location: Chico, CA
Posts: 686
We use mutt to send out bulk PDF attachments. If you can manage to install and configure mutt (a command line unix mail client), it's quite easy to send mails with attachments from a script. Quick and dirty version of what you need in your Applescript is something like:

Code:
set thePDFFiles to every file of (":Path:To:SendFolder:" as alias) ¬
  where (name ends with ".pdf")
repeat with i in thePDFFiles
  set theAttachment to quoted form of POSIX path of (i as string)
  set theMessage to "/path/to/text/messagefile"
  set theEmailSubject to "Another PDF file"
  set theEmailAddress to "desination@isp.com"
  do shell script "mutt -a '" & theAttachment & "' -s '" & theEmailSubject ¬
  & "' -i '" & theMessage & "' " & theEmailAddress
  --delete file or whatever here
end repeat
May require more setup than you want to tackle as opposed to using Mail.app however.
jbc is offline   Reply With Quote
Old 01-19-2004, 06:22 AM   #8
m2uk
Prospect
 
Join Date: Jan 2004
Posts: 5
Thanks. I had a go installing this using info I googled and it seems not to do anything! Thank you for going to the trouble of looking though. I don't suppose someone can "roll" a copy of Mutt into a nice installer and write a few scripts in return for a few beer tokens !

Or, thinking laterally, is there such a thing as a ftp file to email program since I could make the local OSX drive ftp space and then it could do its best to email ?
m2uk is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:13 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.