Mailbox Reader

Modified on Tue, 20 Jan at 5:17 PM

TABLE OF CONTENTS




Mailbox Monitoring and Email Processing

ManagementStudio can monitor a mailbox for incoming emails. This capability supports both replies to system-generated emails and new emails sent directly to the system for further action.

Email messages can be triaged as they are processed. Actions include ignoring certain emails, raising defects, or attaching emails to existing records. For example, out-of-office replies can be ignored or linked to a user’s record for a migration engineer to reference.


Configuring Mailbox Monitoring

Polling Frequency

The frequency with which mailboxes are checked is controlled by the EmailTasks:ReceiveEveryXMin setting in the appSettings.json file.

  • Minimum value: 2 minutes
  • Recommended value: 10 minutes


Email Settings Configuration

Access the email monitoring configuration at:

Administration → Project Settings → Email & Keywords

Configure the following fields:


SettingDescription
Email From Address (1)The address shown in the ‘From’ field of emails sent from ManagementStudio.
Email From Display Name (2)The sender display name for emails sent from ManagementStudio.
Enable Tracking (3)Adds a tracking token to each outgoing email. Allows ManagementStudio to recognise and link replies to the original item (e.g., app, user, or device record).
Monitor a Mailbox / Enabled (4) (5)Enable to start monitoring the specified mailbox.
Create Defects for emails...(6)Enable to automatically raise a defect for emails that cannot be linked to an app, user, or device.
Pre-Processor Script (7)The ID of a custom PowerShell script for custom triage logic. Only one script can be assigned.
Shared Mailbox Alias (8)Enter the alias of a shared mailbox, if applicable, to process only emails from that mailbox.
Mail Server Details (9)Specify the mail server address and port. SSL settings can usually remain on 'Auto', but may be set manually if required.
Mail Authentication (10)Enter the username and password for authenticating with the mail server. Or enter the Azure Tenant Id and corresponding Azure client Id.
Troubleshooting (11)Fields include:
- Last Error: Most recent SMTP error.
- Last Message Id: The ID of the last processed message.
- Last Message Date: Last email processed.
- To reprocess emails: clear both the last message ID and date fields.





Email Processing Workflow

Email Event Handling

After an email is processed—either attached to a record or raised as a defect—the Email Received event is triggered. Emails ignored during processing are not included.

Use this event to automate further actions, such as moving new defects to a specific workflow or assigning them to designated users.


Pre-Processor Script

A PowerShell pre-processor script can be defined for advanced triage logic. The script is executed after the email is read but before actions are committed, allowing custom handling or routing.

  • Define the script in:
    Administration → PS Scripts, Emails, Buttons
  • Enter the script’s ID into the Pre-Processor Script field in Email Settings.


Email Data Provided to Pre-Processor

The PowerShell script receives an array of email objects in ScriptArgs.EventData. Fields available:


FieldTypeDescription
EmailIdintUnique email identifier; use when returning updates.
IgnoreboolSet to true to halt further processing of this email.
IsNewDefectboolSet to true to raise a defect and attach the email.
ProjectIdintAssociated Project ID.
ModuleIdintModule to which the email will be attached.
InstanceIdintInstance within the module for linkage.
MessageIdstringMail server message identifier.
TostringRecipient email address(es).
FromstringSender email address.
SubjectstringEmail subject.
ContentAsTextstringEmail content as plain text (HTML tags removed).
ContentAsHtmlstringEmail content as HTML (included only if "HtmlContent" added to Args1).


Note: ManagementStudio will try to match incoming replies to sent messages and attach them to the originating item (user, app, etc.).


Returning Updates to ManagementStudio


The script must return a hashtable of updates for each email. Only EmailId is required; all other fields are optional depending on the desired processing logic.

Example Email Module IDs


ModuleModuleId
Applications1
UserMigrations2
Devices3
Mailboxes4
BespokeModule5
DeploymentUnits6
Defects8
Contacts12
Tasks14
  • Module and Instance IDs can be set by your script, or supplied by the system when matching a reply to a previous message.

Pre-Processor Script Examples

Example 1: Out-of-Office Auto-ignore

This script ignores emails which are likely out-of-office replies.

$updatesHash = @{}
foreach($email in $ScriptArgs.EventData) {
    $updatesHash.Add($email.EmailId, @{ EmailId = $email.EmailId; Ignore = $email.Ignore; IsNewDefect = $email.IsNewDefect;  InstanceId = $email.InstanceId;  ModuleId = $email.ModuleId; })
}

foreach($email in $ScriptArgs.EventData) {
    if($email.ContentAsText -match "I.*out.*of.*office/ig")  { 
        $updatesHash[$email.EmailId].Ignore = $true        
    } 
}

$updatesHash.Values


Example 2: Attach Email to App by AppId in Subject

This script looks for an AppId:1234 pattern in the email subject and links the email accordingly.

$updatesHash = @{}
foreach($email in $ScriptArgs.EventData) {
    $updatesHash.Add($email.EmailId, @{ EmailId = $email.EmailId; Ignore = $email.Ignore; IsNewDefect = $email.IsNewDefect;  InstanceId = $email.InstanceId;  ModuleId = $email.ModuleId; })
}

foreach($email in $ScriptArgs.EventData) {
    $subject = $email.Subject
    $subject = $subject.Replace(' ', '').ToLower()
    if($subject -match "appid:") { 
        $idStartsAtIdx = $subject.IndexOf("appid:") + 6
        $subject = $subject.Substring($idStartsAtIdx)
        if($subject -match "\d+") {            
            $appId = $Matches[0]
            $updatesHash[$email.EmailId].Ignore = $false
            $updatesHash[$email.EmailId].IsNewDefect = $false
            $updatesHash[$email.EmailId].InstanceId = $appId
            $updatesHash[$email.EmailId].ModuleId = 1
        } else {
            $updatesHash[$email.EmailId].Ignore = $false
            $updatesHash[$email.EmailId].IsNewDefect = $true
            $updatesHash[$email.EmailId].InstanceId = 0
            $updatesHash[$email.EmailId].ModuleId = 0
        }
    } 
}
$updatesHash.Values


Troubleshooting

  • Last Error: Review in Email Settings for SMTP server errors.
  • Last Message Id/Date: Indicates what message was last processed; clear these fields to force reprocessing.



Further Support

For additional assistance, visit the ManagementStudio Service Desk to search the knowledge base or create a new support ticket.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article