I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.
I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.
What's the best way to set this up so I can the contents of the email be pushed into my parsing script?
Many thanks!
Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.
Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.
Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.
tell application "Mail"
set the_messages to selection
repeat with this_message in the_messages
set mytext to content of this_message
end repeat
end tell
Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.
Related
I am trying to make a script that will attach a file to Outlook and then send it. I have that part of the script down fine. My only problem is that for some reason the file isn't attaching. When I look at the replies box at the bottom, it says that it attached and sent the email successfully, however, the file is not attached. What is wrong with my script?
tell write_email
delay 1
make new attachment with properties {file:fileAttachment}
delay 1
end tell
send write_email
I already defined prior to that bit of code this:
set fileAttachment to /Desktop/file-name
I'm trying to get a text document list of any links in a bunch of email messages that reside in the latest Mac Mail.app (OS X 10.10.2 Yosemite), and am simply stumped.
I thought I'd be able to just...
Put a couple of Automator.app actions together in a Service/Workflow,
Select/highlight all the email messages within the Mail.app,
Select that Service or run that Workflow,
And have a text document with every URL/link that could be found within them all.
However, this didn't work.
I figured out how to do this with one email message at a time, but that's not what I want. attached is a screenshot of 3 workflows. The first one is the one that works with just one email message & highlighting all the text in it & running the Service. the other two just simply don't work.
I also notice that the the first shows up in the Service Menu with a single email open; once I highlight more than one email message, the option goes away from the Service menu.
Any tips or tricks?
I figured out how you could reach your goal, start with creating a new service within Automator (input: "No input", application: "Mail")
The first action is Get Selected Mail Messages (Get selected: messages)
The second action is Execute AppleScript with the following script:
on run {input, parameters}
set mailContentList to {}
tell application "Mail"
repeat with selectedMail in input
set end of mailContentList to content of selectedMail
end repeat
end tell
return mailContentList
end run
This script simply walks through the given messages, reads out the content and passes this list to the next action
The third action is Extract URLs from Text. This is listed as "Extract Data from Text" and one of the types of data is "URLs".
And the final action is New TextEdit Document
Save it with a nice name like Extract URLs from selected mails
After that the Service is available inside the Services menu inside the Mail app.
In my test I found a few internal URLs without http:// from links to anchors, so maybe you want to delete all URLs that do not start with http. You can do so by using another action before creating the new TextEdit document:
Filter Paragraphs with options "Paragraphs that start with http" (don't know how these parameters are called in English Automator, sorry)
Feel good, Michael / Hamburg
I'm writing an application where I have to send an email with an attachment using the default mail application.
Before the email is sent, I want the user to be able to edit the text, i.e. the application should just open the mail client with pre-filled recipient and attachment and give the user the opportunity to send it.
At very minimum I need the same effect I'd got if I selected "SendTo/Mail Recipient" from the context menu of the file.
Solutions based on the "mailto:" trick won't work as there are mail clients that do not support the "attachment=" part.
The most complete solution I've found is this one:
http://www.codeproject.com/Articles/3839/SendTo-mail-recipient
but it seems a lot of code for something so simple! (and also crashes when compiled with VS2008)
Is there any other option? It would be ok even if it was an external tool or script (e.g. a .vbs script to be launched with cscript).
I would advise you to use MAPI (Messaging Application Program Interface).
If dotNet can be part of the solution, here's a ready-to-use class in C# : Class for creating MAPI Mail Messages. It would give you something like this:
MapiMailMessage message = new MapiMailMessage("Test Message", "Test Body");
message.Recipients.Add("Test#Test.com");
message.Files.Add(#"C:\del.txt");
message.ShowDialog();
Otherwise, you can always do it in C++ if you feel confortable with it, like this answer suggest.
Then, you will be able to ShellExecute the binary executable and pass it some parameters.
Hope this helps :-)
I'm using a product called "Mail Archiver X" to archive messages from Apple Mail into a custom FileMaker database ("eMailViewerX" - this is the target database that comes with Mail Archiver and is required for the process), from where I copy these messages to my main message archive (another FileMaker DB).
While that process works, it is kind of clumsy (Apple Mail > Mail Archiver X > FileMaker DB #1 > FileMaker DB #2) - and it breaks every time when there is a new version of Apple Mail or OS X until "Mail Archiver X" has been updated by the developer.
So I'm looking for a more simple solution: an AppleScript that will export all messages from exactly one folder ("To Archive") in Apple Mail (4.5/Snow Leopard or 5.0/Lion) as a simple CSV or .tab file, with the following data per line:
Message Sender*
Message Receiver*
Sent Date
Sent Time
Subject
Body
(* Separation of name and e-mail address would be cool, but I understand this may not (always) be possible.)
The only tricky part may be the conversion of carriage returns in the e-mail messages' body into the special character FileMaker expects in TAB or CSV files. In BBEdit, this is shown as \x{0B} (UTF8: 0B). So there would have to be a Find/Replace for that in the script.
No interface, no configuration - just something that spits out all messages from a folder and tells me when it's done.
This does not have to be free (although I wouldn't mind :) - I'd gladly pay for something reliable and simple.
If someone knows about such a script or is willing to write it, I would really appreciate it. I haven't found anything.
TL;DR: I need to export all messages from an Apple Mail folder to a FileMaker-readable CSV file.
There is software called Mail to Filemaker Importer, it's less than $20.
Is this an IMAP mailbox? If so you could use a plugin and download the messages directly into FileMaker records.
A two-part newbie question, guys... I've only just discovered AppleScript and I'm hoping to automagically attach a 'pdf' file to every outgoing (sent) "Mail.app" message.
(Q1) I've got it working successfully in tests running direct from Script Editor - with the file located in the Documents folder - and I'm using:
set pdfFile_Path to ((path to documents folder as text) & "paginatedPDF.pdf")
but the filepath bit confuses me... How would I change this line if I wanted to store my file inside a folder called "PDF's to send" on my desktop?
(Q2) How can I attach the script as a Mail.app rule (the rule options only seem to offer incoming mail message conditions, not outgoing ones)?
Any help/advice much appreciated. Thanks :-)
Have you tried dragging and dropping the PDF straight into your Signature?