Jump to content

Developer Documentation


What it is

IncomingEmail extensions allow your application an opportunity to parse incoming emails and perform an action based on this. For example, Commerce has the ability to parse incoming emails in order to allow clients to email replies to tickets which will automatically be stored as replies within Commerce to the associated support request.

You must set up POP3 fetching of emails or piping of incoming emails into the software in order for the incoming emails to be processed by Invision Community. Setting this up is described in our help guides.

How to use

An IncomingEmail extension has a single method named process(), which will accept an instance of \IPS\Email\Incoming\Email and should return a boolean TRUE or FALSE to indicate if the extension has processed the email or not. All IncomingEmail extensions are looped through when processing incoming emails so it is imperative that you check parameters of the email to ensure it is an email that you need to process. One way to do this is to set up different email addresses for each incoming email extension, and then check the email address within the process method like so

     * Handle email
     * @param    \IPS\Email\Incoming    $email    The email
     * @return    bool
    public function process( \IPS\Email\Incoming\Email $email )
        /* Was this emailed to the right address? */
        $expectedEmail = \IPS\Settings::i()->my_app_incoming_email;
        if( !in_array( $expectedEmail, $email->to ) AND !in_array( $expectedEmail, $email->cc ) )
            return FALSE;

        // Now process the email

You can refer to \IPS\Email\Incoming\Email for details about the class properties and methods, but briefly the most important among these are:

  • $email->to: (array) The address(es) that were emailed
  • $email->cc: (array) Any email addresses that were CC'd
  • $email->from: (string) The sender email address (note that this can be spoofed)
  • $email->subject: (string) The subject of the email
  • $email->message: (string) The body of the email  (HTML sanitized for security purposes)
  • $email->quote: (string) The quoted part of the email, such as when a user hits reply to an existing email (HTML sanitized)
  • $email->attachments: (array) Any file attachments as \IPS\File objects - note that the attachments are automatically also appended to the email body
  • $email->raw: (string) Raw original email  (be careful attempting to use this, as the contents have not been sanitized so you could inadvertently introduce security issues)
  • $email->headers: (array) Raw original email headers

  Report Document

  • Create New...