Grab pictures from IP camera and send by email

I’m trying to grab an image from an IP camera and then send via email. I’m using the following code that I have partially found in this forum. However, I think I’m doing a basic mistake somewhere.

val url = "http://(user):(pass)@192.168.1.110/jpg/image.jpg"
val outputFile = "/home/openhabian/image.jpg"
var cmd = "curl -m 10 -o " + outputFile + " " + url
executeCommandLine(cmd)

val List<String> attachmentUrlList = newArrayList("file://" + outputFile)
sendMail("(email)@gmail.com", "image", "image", attachmentUrlList)

(user, pass and email were replaced in code above.)

I get the following error message:
org.apache.commons.mail.EmailException: Invalid URL set:file:/home/openhabian/image.jpg

The message is clear as the image does not exist when checking the directory.

However, when I run the same code in putty it works fine. The file is created and the then the file is actually sent.

Any ideas?

Dear Andreas,

Im using this code voor my IP camera.
Maybe this can help you.

rule “camerabeeld bij aanbellen”
when
Item Beldrukker changed from OFF to ON
then

var camrechts = “Rechts.jpg”

var deurbelbericht = "Deurbel geactiveerd "+ now.toString ("HH:mm:ss")
executeCommandLine("wget http://user:passwdd@ipadres/Streaming/channels/1/picture -O /tmp/" + camlinks)
 Thread::sleep(3000)



sendMail("emaildres", "Beldrukker voordeur", deurbelbericht, "file:///tmp/" +camrechts)

end

Thanks for the idea. Unfortunately it did not fix the problem. I run into the same error message.

I see that the file image.jpg is created in the folder: \openhabianpi\openHAB-share\openhab2-userdata
However, when I try to create it in the tmp folder the image.jpg is not created. I can’t find the file in the following folder: \openhabianpi\openHAB-share\openhab2-userdata\tmp
This is strange. May be I’m looking in the wrong folder. Any ideas on this?

And then when executing sendMail I get the following error message altghough the file is created in case I don’t do it in tmp folder.

2017-08-05 23:27:31.177 [ERROR] [rg.openhab.action.mail.internal.Mail] - Error adding attachment to email.
org.apache.commons.mail.EmailException: Invalid URL set:file:/image.jpg
Caused by: java.io.FileNotFoundException: /image.jpg (No such file or directory)

This is the code executed in OpenHab 2:

val url = "http://user:pass@192.168.1.110/jpg/image.jpg"
var cmd = "curl -m 10 -o image.jpg " + url
executeCommandLine(cmd)
Thread::sleep(3000)
sendMail("email@gmail.com", "Noon", "Noon", "file:///image.jpg")

Any other ideas?

Maybe you have to add the tmp directory ??