Jump to content
kjf

Add support for mailmate email client

Recommended Posts

I have MailMate set as my default client, but navigating to a file in Alfred, then selecting "Email To" opens up Mail.app.

 

I assume that's because Alfred relies on Applescript and MailMate's Applescript support is weak?

Share this post


Link to post
Share on other sites

I have MailMate set as my default client, but navigating to a file in Alfred, then selecting "Email To" opens up Mail.app.

 

I assume that's because Alfred relies on Applescript and MailMate's Applescript support is weak?

 

Actually MailMate has pretty nice AppleScript support. I looked into it the other morning when kjf originally posted this. Alfred just doesn't support it yet because, well.. we didn't know about it, or at least I didn't. I had never heard of it until this post.

Share this post


Link to post
Share on other sites

Actually MailMate has pretty nice AppleScript support. I looked into it the other morning when kjf originally posted this. Alfred just doesn't support it yet because, well.. we didn't know about it, or at least I didn't. I had never heard of it until this post.

I'd love to know how you found the applescript support - when I looked at the dictionary it only had one custom command. It might be because I'm not super-familiar with Applescript, but I can't even figure out how you would grab a list of selected messages and do something with them.

Share this post


Link to post
Share on other sites

I'd love to know how you found the applescript support - when I looked at the dictionary it only had one custom command. It might be because I'm not super-familiar with Applescript, but I can't even figure out how you would grab a list of selected messages and do something with them.

 

Well, actually what I meant was that the AppleScript command to send a new email was extremely easy to use. There was only one command but it would easily allow for creating new mail messages, attaching files, etc. I ended up removing it so I can't quickly look back now, but I don't remember if there was a mechanism for being able to search through messages via AppleScript or not. I would think not. Something like searching the apps messages could potentially be done by reading an SQLite database or something though.

Share this post


Link to post
Share on other sites

Just to update this thread, I'm adding the ability to add custom AppleScript for open ended email support in the next release of Alfred. This means that users will be able to add support for additional mail clients which Alfred doesn't support by default :)

Share this post


Link to post
Share on other sites

Just to update this thread, I'm adding the ability to add custom AppleScript for open ended email support in the next release of Alfred. This means that users will be able to add support for additional mail clients which Alfred doesn't support by default :)

Is it possible to do so in the current version? How do I set MailMate as default client for sending files/attachements from Alfred?

Share this post


Link to post
Share on other sites

Is it possible to do so in the current version? How do I set MailMate as default client for sending files/attachements from Alfred?

 

It is possible - You'll need to craft the specific AppleScript support for MailMate as all mail clients are different. To get started, create a file called MailMate.applescript (or matching the name of your default Mail client) in the following folder in your home folder:

 

~/Library/Application Support/Alfred 2/Plugins/Email/

 

There should be a single AppleScript method in here which Alfred calls with the following format:

-- Send an email with an attachment
on send_email_with_attachment(ename, eemail, esubject, ebody, eattachment)
end send_email_with_attachment

To help, here is the full AppleScript used for Mail.app:

-- Copyright 2012 RunningWithCrayons. All rights reserved.

-- Send an email with an attachment
on send_email_with_attachment(ename, eemail, esubject, ebody, eattachment)
	tell application "Mail"
		activate
		
		set theMessage to make new outgoing message with properties {visible:true, subject:esubject, content:ebody}
		tell theMessage
			make new to recipient at end of to recipients with properties {name:ename, address:eemail}
		end tell
		tell theMessage
			repeat with aattachment in eattachment
				set filefn to (POSIX file aattachment) as Unicode text
				tell content
				  make new attachment with properties {file name:filefn as alias} at after last paragraph
				end tell
			end repeat
		end tell
	end tell
end send_email_with_attachment

It's worth remembering that eattachment is a list of attachments, not a single attachment, even if there is only one attachment.

 

Cheers,

Andrew

Share this post


Link to post
Share on other sites

It is possible - You'll need to craft the specific AppleScript support for MailMate as all mail clients are different. 

 

Benny from MailMate made the script for me. Works as expected.

Path of the file should be "~/Library/Application Support/Alfred 2/Plugins/Email/MailMate.applescript"

Here is the script:

-- Send an email with an attachment
on url_encode(theText)
	return do shell script "printf " & quoted form of theText & " | xxd -u -plain | sed 's/\\(..\\)/%\\1/g' | tr -d '\\n'"
end url_encode

on create_mailto(_subject, _body, _attachments, _email, _name)
	
	set _to to _email
	if (_name is not "") then
		set _to to _name & " <" & _email & ">"
	end if
	set _mailto to "mailto:?to=" & url_encode(_to) & "&subject=" & url_encode(_subject) & "&body=" & url_encode(_body)
	
	repeat with _attachment in _attachments
		set _filePath to POSIX path of _attachment
		set _mailto to _mailto & "&attachment-url=file://" & url_encode(_filePath)
	end repeat
	
	return _mailto
	
end create_mailto

on send_email_with_attachment(ename, eemail, esubject, ebody, eattachment)
	
	set _mailto to create_mailto(esubject, ebody, eattachment, eemail, ename)
	tell application "MailMate"
		open location _mailto with trust
		activate
	end tell
end send_email_with_attachment

or you can download the file from here.

Share this post


Link to post
Share on other sites

Not an issue.

Andrew, if there could be an option of selecting the email client to be used in Alfred preference, that would make it easier. 

 

This will likely happen in the future. At this point, I wanted to leave it as an advanced configuration as it's the first type of 'plugin' Alfred has had.

Share this post


Link to post
Share on other sites

I believe you just need to put the AppleScript in the right directory and Alfred will automatically use MailMate. Can't remember for certain, as I set it up years ago.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...