Document toolboxDocument toolbox

Mail overview

This pages provides an overview of how mail is handled by Microbizz.

Mail to a contract

Mail sent to XXXX@sanna.microbizz.dk (where XXXX is a contract number) is received by job/jobdaemon.php (on system.microbizz.dk, log in /var/log/mb/jobdemon*) which tries to determine which contract it belongs to. If the contract is valid the mail is stored in JobData, and the job basic/mailimporter.php is set up for the contract.

The mailimporter.php job checks if there are any mails in JobData and calls the Mailgetter class to handle each mail. This will check various destinations for the mail:

  1. the mail may be a reply to a thread/message, and so become a new message
  2. the mail may contain an EDI invoice and should be imported as such
  3. the mail may be recognised by a Mailgetter

Mail import

The CRM module provides mail import from any Imap server. The imported mail are attached to companies or persons depending on the sender and receiver adresses. See the Custmail class for details.

Sending mail from MB

Mails are usually sent using the class MailQueueEntry. This queues the mail and sets up a job basic/mailqueue.php which then handles the actual communication with the SMTP server, as this may take some time.

The script include/class.phpmailer.php provides a SMTP client. The SMTP server details are specified in the config.php file.

Support module

Each support account imports mails from an Imap server. The mails then appear in the support inbox.

Sender

Different parts of MB may be setup to use different sender name+address when sending mail. This is handled by Mail::getSender().

These addresses are used as at reply-to address. The sender address is hardcoded and cannot be changed from within MB.

If sending a question form as PDF due to an action, and the form was filled in on a task, the sender will be the active user.

SMTP server

It is possible for each contract to provide its own SMTP server for sending mail. The details about the mail server are stored in a "property" in DB; when Microbizz tries to send a mail it first tries to read the setup from the property and overwrite config.php.

The setup with a status that is initially set to "pending"; the setup will only be used when the status is "accepted". When the status changes a mail containing a link is sent to the active user. Clicking on the link will change the setup status to "accepted".

Bounce

If a MailQueueEntry cannot be sent, or is sent but an errors is later returned, the mail is said to have "bounced". This is handled by MailQueueEntry→bounce() which may report the error back to the part of MB that sent the mail, eg. the Invoices module. The details about the bounce server are specified in config.php.

It is possible for each contract to provide its own bounce server. This works much like the SMTP setup.

Test mail account

There is a test mail account which may be used when testing if reading mail works.


Imap

The class Imap handles the interface to an Imap server, it uses the ImapNew class.

The class ImapNew can connect to an Imap server, either through PHP's builtin imap_xxx() functions or via the external library Javanile/Imap2/.

The reason for the use of Javanile/Imap2/ can be found here.