Automatically adding attachments to all outgoing mail messages - applescript

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?

Related

Running Excel Scripts on Outlook Attachments then sending processed files

TL;DR: I want to extract an Excel attachment from an Outlook message, automate an Excel script on the unprocessed reports, and then send the output in a new email message.
I have reports from Amazon that I have sent to a specific email on my Outlook folder each month.
I set up Power Automate to trigger whenever an email with an attachment is received in this folder.
I want to take the attachment in this Outlook email and run an Excel script that I build on Excel Desktop (not an Excel application macro) to format the data.
And then I want to send the output/result (scripted email attachment) as the body of an email out to clients.
I've gotten the first and last parts to run, but I can't get the script to process the file, that's the phase that always breaks that automation.
Things that I think might be causing the issue:
Do I need to extract the attachment from the email and save it as a file before I can run the Excel script on it?
Does the attachment need to be saved through Share Point to be later referenced by the Excel script?
Does the script need to be on the same or different cards as previous steps?
I've seen people run the Excel script through a Scope.
I've also looked at every available YouTube video to troubleshoot this: some go over certain steps in the process, but I'm having a hard time threading everything together.
Other Things I've Tried
I also tried to build a macro that does the same thing as my Excel desktop automation, and then wrote VBA code so each time a new sheet is opened the same macro is run, processing the data. But I couldn't get it to run on any new future sheet that I open, even when writing the VBA auto-open code in Module as well as This Worksheet.
I'm open to any method that will make this work.
Get email (V2) - Message ID
#{triggerOutputs()?['body/id']}
Apply to Each - Select an output from previous steps
#{outputs('Get_email_(V2)')?['body/attachments']}
Create File - File Name
#{items('Apply_to_each')?['name']}
Create File - File Content
#{items('Apply_to_each')?['contentBytes']}
Move or rename a file - File (make sure you add .xlsx for Destination File Path)
#outputs('Create_file')?['body/Id']
Run Script - File
#outputs('Move_or_rename_a_file')?['body/Id']
Get file content - File
#outputs('Move_or_rename_a_file')?['body/Id']
Send an email (V2) - Attachments Name-1
#outputs('Move_or_rename_a_file')?['body/DisplayName']
Send an email (V2) - Attachments Content - 1
#body('Get_file_content')?['body']

Email Alert for Inserting/updating/removing files inside folder in windows7

i have above mentioned case happen at our company, they need to know under certain folder whether its shared or not if any files inserted or removed or update to send alert by email periodically for that action, any thought an ideas please
You can fairly easily create an application in C# that monitors a folder using the FileSystemMonitor class:
https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx
With that you can then have it perform whatever actions you want.

Mac Automator/Applescript(?) to extract URL's from Mail messages

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

Windows SendTo from script

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 :-)

Automator / AppleScript to process incoming emails in Mac Mail

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.

Resources