Automating Email Notifications for Mailbox Storage Monitoring

Aran Billen 826 Reputation points
2024-04-17T12:01:56.5133333+00:00

Hi everyone,

I'm looking to automate a task where I receive an email notification when a specific email mailbox reaches 80% of its storage capacity. After researching, it seems that using Azure Automation Accounts would be the way to go.

Firstly, I'm wondering whether I should use a private endpoint or a public one to interact with Exchange Online. Does it matter which one I choose?

Secondly, I'm unsure if the PowerShell script differs when running it within a runbook in Azure Automation Accounts. If it does, what adjustments do I need to make? I've come across mentions of using an App ID, but wouldn't Exchange already be part of the app registration within Azure?

Additionally, I'm not sure how to achieve my desired outcome of receiving an email notification when a specific email is 80% full. Currently, I'm able to connect to Exchange Online using:


Connect-ExchangeOnline -UserPrincipalName me@test.com

Get-MailboxStatistics -Identity no-reply@test.com | Select DisplayName, TotalItemSize

This displays the mailbox size, but I'm unsure how to email this information to myself.

Could someone please provide guidance on how to accomplish this? Thanks in advance for your help!

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,257 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 25,675 Reputation points MVP
    2024-04-17T12:12:07.1733333+00:00

    You might want to consider the approach similar to this one (which eliminates the dependency on Azure resources):

    https://learn.microsoft.com/en-us/answers/questions/1605301/report-when-mailbox-reaches-a-particular-size


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


  2. AnuragSingh-MSFT 21,386 Reputation points
    2024-04-25T07:22:42.3033333+00:00

    @Aran Billen, Thank you for your replies.

    While one of the approaches is mentioned above, I am not sure why "Send-MailMessage" cmdlet is not working in your environment. I will suggest running it from your local machine to test if this cmdlet works. Also, notice that this cmdlet is obsolete, hence not recommended to be used. For details, see Send-MailMessage: Description

    The following contains information that should help answer queries you had about Azure Automation:

    1. Private endpoint or a public one to interact with Exchange Online - It depends on your use case, policies and compliance standards being followed in your environment. Furthermore, I dont think private end point is available with ExchangeOnline - hence the default public endpoint mode of connection should work well. For more details, see Microsoft 365 endpoints.
    2. Running script in Azure Automation - There are some differences in the way authentication is handled in Azure Automation as interactive login is not available. Therefore, generally the authentication part is where the difference happens. As you start with Azure Automation, I would suggest the following tutorial and article to get familiar with the authentication part:
      1. Tutorial: Create Automation PowerShell runbook using managed identity
      2. Using a system-assigned managed identity for an Azure Automation account
    3. For your use case scenario, please follow the link below. It contains step by step guidelines for connecting from Azure Automation to Exchange Online PowerShell using the managed identity - Use Azure managed identities to connect to Exchange Online PowerShell
    4. For sending email from PowerShell (and Azure Automation), you could also consider GraphAPI - user: sendMail

    The information above should provide building blocks for your entire solution.

    Hope this helps.

    If the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.