Trouble sending mail with attachment

@J-N-K I’m having trouble using the OH2 mail binding to send an email with an attachment. Do you see anything wrong with what I’m doing below?

Here’s a code snippet.

    val String imageUrl = ""
    //val String imageUrl = "file:///path/to/another/image.jpg"
    //val String imageUrl = "file:///path/to/a/text/file"

    //val mailActions = getActions("mail","mail:smtp:gmail")
    val mailActions = getActions("mail","mail:smtp:anothermailserver")

    mailActions.sendMail("", "Email without attachment", "Email content without attachment")

    mailActions.sendMail("", "Email with attachment", "Email content with attachment", imageUrl)

When executing the above, I get two emails. The first email correctly contains the supplied subject and content text. The second email contains the supplied subject text, but no content and no attachment.

I’ve tried this with two different mail servers with the same result.

When viewing the raw source of the second received email, this is what I see.

[snip mail headers]
Subject: Email with attachment
MIME-Version: 1.0
Content-Type: multipart/mixed; 

I’m on build 1750 with this version of the mail binding.

299 │ Active │  80 │      │ org.openhab.binding.mail

Is anyone using the OH2 mail binding to send attachments successfully? Can you comment on my usage above?

The example in the docs shows List of attachment url strings

val List<String> attachmentUrlList = newArrayList(
val mailActions = getActions("mail","mail:smtp:sampleserver")
mailActions.sendHtmlMail("", "Test subject", "<h1>Header</h1>This is the mail content.", attachmentUrlList)

Have you tried with a one-entry list?

Yes, I did try that. And, besides, there’s no real difference between calling the API with a single url string versus the one-element list. Internally, the code converts the string url to a one element list.

I don’t suppose the old 1.x mail action would tell you any more, either.

I’ll probably try installing that.

I installed the OH1 mail action, and I was able to successfully send emails with attachments.

Therefore, I can only assume that I’m doing something wrong, or there’s an issue with the OH2 binding w.r.t. attachments.

I’m experiencing the same.
It worked fine in 2.5.0M2 but once I upgraded to 2.5.0M4 (I skipped M3) the images and body were no longer sent.
I upgraded to 2.5.0M5 but the result is the same.
Since I didn’t change anything in my rules I can only assume something broke.

Thanks for letting me know.

I opened an issue here.

1 Like

M2 was published in early August, so it had to be something that changed since then.

I‘ll try to have a look. Probably on Friday.

Thanks. In the mean time I’ll look through the commits since August to see if there’s anything obvious. I took a quick look the other day, and the only thing I saw that looked material was the charset change.

Is it working with local files and only fails for remote/web files?

I only tested with URL’s from IP cams on a different subnet of my local network: “http://” + uniFiVideoGarageIp + “/snap.jpeg”

Is there something specific you would like me to test?

@J-N-K I’ve tried with local files (using file://) as well as remote files (using http://). The first post shows the various URLs I’ve tried.

just download 2.5.M6 but problem remains:

  • no attachment parameter -> ok
  • with paramter (e.g. url string) -> even the message text is empty

is this the solution?

yes it is - just restart once more after the proposed actions

Hi Mark,

sorry for the abscense… and thanks for creating an issue and following up.
I upgraded to RC1 today and rebooted and now everything works again as before.
The changes made have fixed this one for me.