Channel use for sending email attachments

Reviewing the few mentions of channels here and in Bitbucket, all the old channel statements and functions have been brought across from P6, along with a number of modules, but currently it appears that new channel modules can’t be registered or used, and there doesn’t seem to be any channel module registration functionality built into the View Organiser as there is for custom statements.

There are three email modules in the channels that reside in PX, none supporting enclosures. Jim has suggested that he probably wouldn’t enable enclosure support himself, Dave has commented that it could be done with AppleScript in a PX procedure, and James Cook gave details of how he was able to achieve this using Python inside a PX procedure.

Even though new channel modules don’t seem to be supported, it seems to be possible to modify the code in existing modules. Would any changes made to procedures in existing modules be overwritten with new PX releases?

Or would it be better to ignore channels as Dave and James suggest?

Sending email enclosures from Panorama is a crucial feature for my business, and seems to be so for other Panorama users. It would be great to have a solid, easy to use implementation of this feature.

David Duncan

We have just been able to send emails with attachments from PX using Dave’s “Email w Attachments” code plus some other code, but without accessing any channel data. This was a test of PX and AppleScript capability and needs refinement, after which I hope to use the code as a custom statement.

Panorama’s channels system doesn’t support email attachments – it didn’t in Panorama 6 and still doesn’t in Panorama X. I’m not sure if it ever will or not.

For the past year or two I have been using a service called Mailgun to send emails from Panorama, including emails with attachments. This service has worked really, really well for us.

I have so many projects on my plate that there is no way that I can make this available at this time. However, for those of you that are willing to do a little bit of programming and network configuration, Mailgun uses a simple HTTP interface that is very well documented. It’s pretty easy to set up with Panorama’s url( functions, or with curl. Mailgun is free for up to 10,000 emails a month so it is a pretty unbeatable deal. The trickiest part was getting the network settings configured with DKIM and SPF records so that your email doesn’t bounce as spam, but that has nothing to do with Panorama. Mailgun does have good documentation for that, though.

Panorama X, as well as 6, can send email with attachments using Python. It works well and works reliably.

It’s not something that most users will find easy to set up, and it’s not soemthing I can give simple instructions for. What I will do, is make it a point to use my highly tailored process to create a generic emailer with a set of required variables to make it work for anyone.

As I currently use it, it responds intelligently to embedded graphics and attachments, including however many exist whether it be none or many. Just like any email app.

Python is definitely one way to go – that’s what I used to use. What I like about mailgun is that once it is set up I found I got better results as far as emails actually being delivered and getting thru to the recipient, that is their only business and they are very good at it. (Actually, I think it is part of Rackspace so it is not really their entire business, but you get the idea.) We used to have a lot of complaints from users that weren’t receiving emails for things like order confirmations, now that has dropped to virtually zero.

We use email to distribute a number of daily Panorama 6 reports (mostly PDFs) between our four factories and our national office and management. Emailing using the combination of Apple Mail channel, the SendEmail custom statement and Dave’s “Email w Attachment” channel module has been extremely reliable. We send no bulk mail and only very low volumes of mail outside the business, so I don’t think it’s necessary for us to use a service like Jim does, unless PX was not able to do what 6 had.

Fortunately it can. When we’ve finalised our PX implementation as a custom statement I’ll make it available here.

David Duncan

Hi David, have you ever posted your method for sending emails with attachments in PanX? That is something that I will need to do, if possible. Thanks.

I posted just such a utility for Pan X in March. See Mailbox in the Database Exchange.

Tom

I don’t think that in the event I ever did — until now I’ve had response whatsoever in fact.

I have what you need to do this in PX. It’s midnight here in Sydney right now so I’ll send you this info in full sometime tomorrow when I can think clearly.

David

Tom, I have the email with attachments file ready for use.

I was very glad to see James Cook’s Python solution as I was always worried about Apple’s support of AppleScript. It’s great to have alternatives.

David,

Thanks. That works great.
Only one issue for me: it will not work correctly if the file path has a space in a folder name. Do you think there is any way to change that behaviour?
I am sure that I can find a work around if this is not changed, so it is not a big problem.

Tom

It’s been some years since I cobbled these sections of code together, but now you mention it I recall that it didn’t work if the attachment filename contained a space. I may have had the same problem with the file path, because I originally adapted the code to expect the attachment file/s to be on the desktop, and there are no spaces in that path. One of the things I did over the last couple of days to make my version of the file distributable was to enable any file path (forgetting about ones containing spaces, as you have discovered).

Looking at the original code that I borrowed, spaces are used as array separators in Attachments lists, I assume for use in AppleScript. Spaces in the parameter would definitely stuff things up.

One fix would be to require the attachment file/s to be placed on the desktop (or alternatively in the Documents folder), and reinstate the desktop (or Documents folder) as the file path leading to the attachment file/s. Do you think either would be preferable?

I’ve deleted the link to EmailAttachments file for the moment.

I think you can take care of the spaces in the file path using quoted form of to convert it.

set myFilepath to quoted form of "/Users/gyonaites/Desktop/My Archive/Mail Test.scpt"

HI David,

I am using the statement to send all of the files in a particular folder, each to a different person. To solve the 'spaces-in-the-path' issue, I used Panorama commands to copy the folder to a new desktop folder, send the files as attachments from there, then delete the new folder. An acceptable method, I think.  

Tom

That method is ok as long as the file names themselves don’t contain spaces, only the folder names.

I think David removed the download from his DropBox, so I can’t look at the source now. But it certainly shouldn’t be difficult to fix this problem by adding quotes.

I’ve reinstated the EmailAttachments.pandb file. It has better documentation and a new dropbox link:

https://www.dropbox.com/s/2pohw68pipgw7sp/EmailAttachments.pandb.zip?dl=0

Apparently this dropbox item has been deleted.

I will add the statement to the Database Exchange, but it won’t be until late in the month as I’m fishing in the NZ Southland.

Could you possibly show some simple code for sending via HTTP with Mailgun? Their examples all speak to using Curl and in another post you recommended using URL( whenever possible. I am not getting this after banging on it for a while.

This is a case where it is not possible. Well, it is possible for simple emails, but not if you want to send both plain and HTML text. Unfortunately, the url( function does not current support the --form-string option (I haven’t figured out how to do that). Fortunately, it is still possible to use curl via the shellscript statement or function.

local mgResponse
shellscript 

{curl -k --user 'api:key-REDACTED' }+
{https://api.mailgun.net/v3/mg.YOURDOMAIN.com/messages }+
{-F h:reply-to=}+ereplyto+{ }+
{-F from='Your Name <you@yourdomain.com>' }+
{-F to=}+erecipient+{ }+
{-F subject='}+replace(esubject,{'},{'\''})+{' }+
{-F text='}+replace(textTemplate,{'},{'\''})+{' }+
?(htmlTemplate<>"",{--form-string html='}+htmlTemplate+{' },"")

,mgResponse

For just plain email, it is possible to use the url( function.

let mgRequest = initializedictionary(
    "h:reply-to",ereplyto,
    "from","Your Name <you@yourdomain.com>",
    "to",erecipient,
    "subject",esubject,
    "text",textTemplate
    )
let mgResponse = url("https://api.mailgun.net/v3/mg.YOURDOMAIN.com/messages",
    "user","api:key-REDACtED",
    "post",mgRequest)

Hopefully someday I’ll figure out how to implement the --form-string option and it will be possible to eliminate the need for curl in this application.

1 Like