[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Mail scripting

Posted on 2009-05-04
8
Medium Priority
?
497 Views
Last Modified: 2012-05-06
Okay, I have a unique requirement.

I get 800 emails per day, and I want to sort them by the first 3 characters of the attachment name.
95% of them have an attachment that starts with 3 numbers that indicate what group the email belongs to.  The attachment name might be "01807.jpg"

I would like to sort the emails into individual folders based on the attachment names.  "01807.jpg" makes a folder named 018 and puts the message in there.

I was provided this applescript, but I will admit- I am not a programmer and understand NONE of it, and need to know what to do with it, aside from saving the script file.  I've done that.

Any help to make this work is appreciated.

The mail is in a MAPI mailbox named "WORDPRESS"  and the folders can be under that mailbox.

Thanks for the help!

using terms from application "Mail"
	on perform mail action with messages TheMail
		tell application "Mail"
			repeat with ThisMail in TheMail
				if (count of mail attachments of ThisMail) > 0 then
					set AttName to name of first mail attachment of ThisMail
					set AttName to (items 1 thru 3 of characters of AttName) as string
					if not (exists mailbox AttName) then
						make new mailbox with properties {name:AttName}
					end if
					move ThisMail to mailbox AttName
				end if
			end repeat
		end tell
	end perform mail action with messages
end using terms from
 
using terms from application "Mail"
	on run
		tell application "Mail" to set sel to selection
		tell me to perform mail action with messages (sel)
	end run
end using terms from

Open in new window

0
Comment
Question by:TIgerV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 5

Accepted Solution

by:
AGoodKeenMan earned 2000 total points
ID: 24300718
That should work fine. Goto /Applications/AppleScript/ and open the AppleScript Utility, you will find an option to enable the script menu in menu bar. Then with Mail active, open the script menu and select "Open Mail Scripts Folder" and save your script into this folder.
Now with all the new emails selected run this script from the script menu.
0
 

Author Comment

by:TIgerV
ID: 24300775
Outstanding!  Thank you very much.  I am still testing a few things, but I think this is gonna do exactly what I need.
0
 

Author Comment

by:TIgerV
ID: 24300797
Okay, it is working, but.....

Saving the mail to "on my mac" in a folder.  How do I tell it to save it to a folder on the IMAP account?

If this is working tonite (974 emails), this should be a 1,000 point question.  :-D

Thanks!
0
What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

 

Author Comment

by:TIgerV
ID: 24300807
I just found out I can select them and Drag them back, but it would be quicker and easier to allow them to remain on the IMAP.
0
 
LVL 5

Expert Comment

by:AGoodKeenMan
ID: 24302066
Ok I'm working on it, I need the name of your IMAP account?
0
 
LVL 5

Expert Comment

by:AGoodKeenMan
ID: 24302407
Try this one and see how it goes. You will need to add your IMAP account name on line 7.
using terms from application "Mail"
	on perform mail action with messages TheMail
		
		-- In the line below replace "myAccountNameGoesHere"
		-- with the name of your IMAP account
		
		set IMAP_Account to "myAccountNameGoesHere"
		
		tell application "Mail"
			tell account IMAP_Account
				repeat with ThisMail in TheMail
					if (count of mail attachments of ThisMail) > 0 then
						set AttName to name of first mail attachment of ThisMail
						set AttName to (items 1 thru 3 of characters of AttName) as string
						set AttName to "WORDPRESS/" & AttName
						if not (exists mailbox AttName) then
							make new mailbox with properties {name:AttName}
						end if
						move ThisMail to mailbox AttName
					end if
				end repeat
			end tell
		end tell
	end perform mail action with messages
end using terms from
 
using terms from application "Mail"
	on run
		tell application "Mail" to set sel to selection
		tell me to perform mail action with messages (sel)
	end run
end using terms from

Open in new window

0
 

Author Comment

by:TIgerV
ID: 24303187
Thanks.  I'll put that in and see how it goes.   I will get the mail blast at about 4pm.
0
 

Author Comment

by:TIgerV
ID: 24303241
OUTSTANDING!  You have done it.  

Thank you very much.  I tried it with a test mail that I had in the queue from a while back.

Tony
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question