This page is part of archived documentation for openHAB 2.5. Go to the current stable version

# Mail Actions v1

This add-on provides SMTP services so your rules and scripts can send emails.

# Actions

  • sendMail(String to, String subject, String message): Sends an email via SMTP.
  • sendMail(String to, String subject, String message, String attachmentUrl): Sends an email with attachment via SMTP.
  • sendMail(String to, String subject, String message, List<String> attachmentUrlList): Sends an email with one or more attachments via SMTP.

The to parameter can contain a semicolon-separated list of email addresses. Email addresses can be specified in one of these formats: either "[email protected]" or "First Lastname <[email protected]>".

# Configuration

This action service can be configured via the services/mail.cfg file.

Property Default Required Description
hostname Yes SMTP server hostname, e.g. "smtp.gmail.com (opens new window)"
port 25 (resp. 587 for TLS/SSL) No SMTP port to use
username if the SMTP server at <hostname> and <port> requires authentication SMTP user name
password if the SMTP server at <hostname> and <port> requires authentication SMTP password
from Yes Email address to use for sending mails. The email address can be given as [email protected] or from=First Lastname <[email protected]> (do not use quotes).
tls false No true if STARTTLS is enabled (not required) for the connection
ssl false No true if SSL negotiation should occur on connection. Do not set both tls and ssl to true. If true is used here, the port will automatically be set to "465".
popbeforesmtp false No set to true if POP before SMTP (another authentication mechanism) should be enabled. Username and password are taken from the above configuration
charset platform default No Character set used to encode the message body

# Examples

import java.util.List
...
val List<String> attachmentUrlList = newArrayList(
  "http://some.web/site/snap.jpg&param=value",
  "http://192.168.1.100/data.txt",
  "file:///tmp/201601011031.jpg")
sendMail("[email protected]", "Test", "This is the message.", attachmentUrlList)