Mail

Description

The Mail object can be used to send emails.

› Inherits:Object

Properties

body

This property holds the body of the email. This contains the message.

› Type:String
› Signal:bodyChanged()
› Attributes:Writable

configuration

This property holds the SmtpConfiguration used to connect to the server.

› Type:SmtpConfiguration
› Signal:configurationChanged()
› Attributes:Writable

error

This property holds the most recently occurred error or Mail.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorData

This property holds all error data of the sender process, when sending has failed.

› Type:String
› Signal:errorDataChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

from

This property holds the name of the sender.

› Type:MailAddress
› Signal:fromChanged()
› Attributes:Writable

subject

This property holds the subject of the email

› Type:String
› Signal:subjectChanged()
› Attributes:Writable

to

This property holds the name of the recipient.

› Type:MailAddress
› Signal:toChanged()
› Attributes:Writable

Methods

send()

This method sends the email with the configured data.

› Returns:Boolean

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

sent()

This signal is emitted when the operation is done, the email was sent successfully.

Enumerations

Error

This enumeration describes all errors which can occur in Mail objects. The most recently occurred error is stored in the error property.

Name Value Description
Mail.NoError 0 No error occurred or was detected.
Mail.ConfigurationError 1 Invalid or incomplete configuration.
Mail.EmptyFromError 2 No sender in property “from” specified.
Mail.EmptyToError 3 No recipient in property “to” specified.
Mail.EmptySubjectError 4 No subject specified.
Mail.SystemError 5 Error starting the SMTP system process.
Mail.SendError 6 The email could not be sent, likely due to a wrong configuration.

Example

import InCore.Foundation 2.5
import InCore.IO 2.5

Application {

    DigitalIO {
        id: input
        direction: DigitalIO.Input
        index: DigitalIO.IO1
        onValueChanged:
            if( value === true ) {
                mailer.send()    //send mail
            }
    }

    Mail {
        id: mailer
        //SmtpConfiguration
        configuration {
            server: "mail.example.org"
            port: 25
            tls: true
            username: "sender"
            password: "c5ypt!cP4ssw0rd"
        }
        //MailAddress
        from {
            name: "Test sender"
            address: "sender@example.com"
        }
        to {
            name: "Test recipient"
            address: "recipient@example.com"
        }
        subject: "digital input on"

        body: "Dear Customer\n\n
                the digital input value had an rising edge."

        //error handling
        onErrorDataChanged: console.log( "sending failed with data:", errorData )    //check for sending failure
        onErrorChanged: console.log( errorString )            //other errors
    }
}