Mail: can't send email attachment when attachmentUrl has an embedded username & password

So I’m trying to retrieve a still image from a camera and email it… Should be easy, right?

mail wiki says:

sendMail(String to, String subject, String message, String attachmentUrl): Sends an email with attachment via SMTP.

Seems easy enough. A static jpg gets emailed pretty easily:

sendMail("","subject","message body","")

Problem happens when the url is of the form:

Winds up with an invalid url message:

2016-03-28 21:42:58.372 [ERROR] [nhab.action.mail.internal.Mail] - Error adding attachment to email.
org.apache.commons.mail.EmailException: Invalid URL set:http://(redacted):(redacted)@(redacted)/image/jpeg.cgi

Seems like I should be able to do a two-step method, by manually retrieving the image with sendHttpGetRequest, store it in a string, then pass the string as the attachment. Sadly, either I don’t understand how to do that or it doesn’t work either:

var String http_response
http_response = sendHttpGetRequest("http://(redacted):(redacted)@(redacted)/image/jpeg.cgi")
sendMail("","test email subject","message body.",http_response)


2016-03-28 21:47:10.590 [ERROR] [nhab.action.mail.internal.Mail] - Invalid attachment url. no protocol: ???? ►JFIF      ?? C ♠♦♣♠♣♦♠♠♣♠♠
(rest of binary jpeg data clipped)

Any suggestions on how to accomplish this?

Nobody has any ideas how to send an attachment that’s already been retrieved into a string object?

Hello! This rings a bell:

1 Like

Thanks! I’ll give that a shot.

1 Like

@TheKorn, were you able to send an attachment with embedded username and password? Have you found a solution?

I actually had to go look at what rule I was using to figure out what I did…

…apparently I decided I had bigger fish to fry, and just took off the password from the still image for now. D’oh, guess I should put that on my list of things to circle back to. (Sorry!)

Attachment URLs (when sending mail from a rule) cannot have username:password embedded in them, as it’s not supported by the underlying library. But you could fetch the file you want to attach to the local file system, and then attach it to your email using a URL like file:///tmp/myfile.jpg.


I’ve actually just posted something similar in another thread (here) as I’m getting odd file attachment names.

Also, how do you save the file to local file system? In the other thread you mention ‘executing curl’ to do that but I have no idea what that means!

Lastly, is there anyway to capture an image from a video stream and send that (for IP cameras that don’t provide snapshot capability)?

Many thanks,


You’re posting in a five year old thread about a completely different mail Action (v1) to the one you are using in OH3 and in a different rules environment (DSL) to the one you are using (javascript).

great job using the search function Greg but…
cross posting to ancient threads is kind of poor forum etiquette…
did your question not get answered in the other thread?

@moderators please lock this one

Sorry about that. I had so many screens open and posted to the wrong one.

1 Like