sendMail URL attachment - set extension


I am using sendMail in a rule to send me an image from my webcam. Unfortunately, I get an “Attachment” file, with no extension. My phone dislikes this and won’t open it easily without a complex saving and renaming process. How can I tell sendMail to send me the attachment with a specific name or even just add .jpg to the end?

I’ve made a pull request with a link to a JAR to test that ought to name the attachment as meaningfully as possible. It also supports a new version of the sendMail action that takes a List<String> instead of a String so you can attach multiple attachments.

Please try it and let me know if it works. I would also be interested if you could successfully attach multiple attachments to one email.

The code change will take the last bit of the attachmentUrl and use it as a name for the attachment. So if the last bit (before any parameters) is snap.cgi, for example, then you will get an attachment named snap.cgi, which is also not terribly useful in an email client. But if the last bit is snap.jpg, it should work correctly in your email client.

In the case where the the attachment name’s extension is not the same as the type of file and you would like it to be, I recommend pulling the attachment to the openHAB server’s /tmp directory first in your script or rule (possibly exec’ing curl to do that), naming it as you want to see it attached, and then using a URL like file:///tmp/mylovelyimage.jpg to attach it to the email.

Makes sense. I hadn’t considered that a file:// URL would work. I’ll wait for the code change to make it into Cloudbees then will upgrade and test.


I’ve just been using this functionality to send me an email with a photo attached when certain events happen but the attachment has a strange extension. I’ve had a look at the two pull requests relating to this (here and here) but I’m still having an issue. The URL I get the image from is

http://[internal ip address]/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=[USR]n&pwd=[PWD]

and the file comes through with the name ‘CGIProxy.fcgi’ which means it doesn’t automatically open in an image editor.

Is there any way we can define what the attachment is called and override the current logic? It would also be nice if we could append a timestamp to the attachment filename.

Many thanks,


Hi Ben,

One alternative is to retrieve the image to a local file, name it as you want it to be named, and then attach it using a URL like file:///path/to/file/20160705.jpg. This could all be performed in the rules language.

Related: Some email clients, like GMail, don’t mind image attachments having extensions like .cgi, since they detect the contents as being an image.


Thanks for your quick response! I’m afraid I’m a bit new to OpenHAB rules and whilst I’ve had a look through the documentation and sample rules, I can’t find any useful guidance to show how I might retrieve the image to file. I was wondering if you might be able to point me in the right direction?

I’m familiar with some programming languages but Java isn’t one of them (although C++ is). Should I be looking at XBase and XTend?

Thanks in advance,


1 Like