Find, Copy and Paste Text From Apple Mail App Internal Headers

When it doesn't work, do you know why?
Have you looked at the Raw Source to find the auth-sender?

If you have, then if you will post the text around that section I'll see if there is a tweak to the RegEx that will match it.

Received: from tmsmtp03oc.fakeemail.com (tmsmtp03oc.fakeemail.com [209.67.128.156])

by mlpnf0119.laposte.net (SMTP Server) with ESMTP id 4B7nhm5Ft5zKm40;

Sat, 18 Jul 2020 01:42:00 +0200 (CEST)

Received: from mail pickup service by tmsmtp03oc.fakeemail.com with Microsoft SMTPSVC;

Thu, 16 Jul 2020 07:53:02 -0700

auth-sender: muljavier@fakeemail.com

Received: from 10.1.106.121 unverified ([10.1.106.121]) by tmsmtp03oc.fakeemail.com with M2W SMTP Server;

Here is my amateurish attempt to fix my original Macro. I added the steps below to the end of it.

Screen Shot 2020-07-20 at 12.08.04 PM

The only problem I'm running into is that sometimes, between the colon and the email address exists

  • 1 Space
  • 2 Spaces
    or
  • 0 Spaces

And maybe we need to add some pauses to the macro for it to run smoothly?

I just tested that string with the below RegEx, which is part of my Maco, and it found the email. Test it for yourself. Open the below link and paste this string at the bottom.

Pauses have nothing to do with Regex.

The current Regex:
auth-sender:\h+(.+)\h*\R*

will match "auth-sender:" and then ONE or more spaces or tabs.

Change it to this to allow ZERO or more:
auth-sender:\h*(.+)\h*\R*

In the future when you post source text, please use the Forum Code Block with a language of "text".

1 Like

@JMichaelTX, I just wanted to thank you again. I use this macro at lease 20 to 30 times during the workday. Thank you, it significantly improved and sped up my workflow!

1 Like

Is there a way to move the mouse to a specific location on a secondary screen? I'm trying to add to this macro.

See Move or Click Mouse action and use the SCREEN function to get the position on the target screen.

I'm sorry I must be missing something, I don't see an option for an external monitor in the move or click action. Please show me again?

Screen Shot 2020-08-03 at 2.04.16 PM

Choose "absolute position", and enter something like this:
SCREEN(2,MidX) and SCREEN(2,MidY)
where "2" is the target screen#.

If you only have one external monitor, you can use "External" instead of "2".

See SCREEN function for other choices.

1 Like

Thank you so much!

1 Like

I'm having trouble with the screen again because I accidentally edited the working macro.

My external screen is to the left of the main screen. Is there a way I can enter an x and y coordinate once on the external screen?

Hi @gglick

Looking to modify this to get the sender's address from an email open in Apple Mail on the clipboard that will be used by Hazel to create a new rule.

This works up to the last step as when it had a display text action as the last step it displayed the sender's address.

I also tried
image

and set system clipboard to %Variable%Local__EMail% which doesn't work either. I get "COULD NOT FIND" which I see is the original variable being set.

I also see in the Insert Token list in the Mail section one called Mail Sender. Might I use that to more simply extract the sender's address?

I'm guessing the Regex action is setting the text search result of the %MailRawSource% variable to a variable called Local_EMail. Is that accurate?

I looked in the actions in the wiki and don't have the distinctions to understand and use what's there.

Thanks!

Sender to Clipboard.kmmacros (12 KB)

Hey @BernSh,

Yes, fortunately, you don't need regex to get the sender's address in Mail. As you discovered, Keyboard Maestro does already have a token for that, along with numerous other properties besides the mail's raw source:

So yes, if you just want to get the sender's address onto the clipboard, this macro could be drastically simplified like so:

Thanks for quick reply. Exciting idea and this gives a blank clipboard. See something off or maybe restart KM or the Mac? Running 10.15.7 and KM 9.1

Keyboard Maestro Actions.kmactions (8.9 KB)

No problem. Here's one troubleshooting idea: open KM's Value Inspector window (6 while in the editor), put the Mail Sender token there, and see what it says while selecting and opening different messages in Mail:

If nothing shows up there, make sure that KM has permission to automate Mail in System Preferences > Security & Privacy > Privacy > Automation:

Wow, that inspector is cool! Thanks!

I think I found the issue. It works when I either select an email from the list of emails IN Mail or select an email opened from WITHIN the Mail app. It fails with emails that I've dragged out of Mail into a folder and then open from within that folder even though Mail is opening the email.

Ideas?

Sorry, I don't use Mail much to begin with, and I've never used that feature of it, so I'm afraid I can't be much help there.

Thanks for looking at this! @gglick

Hey @peternlewis

The %MailSender% Token works from within the Mail app but not with Mail dragged from Mail app into the Finder and then opened within the Finder. Is this expected?