However, for some Microsoft/Outlook accounts (like GoDaddy), it’s possible to re-enable them.
Enabling SMTP
Step 1: Launch Powershell In Administrator Mode

Step 2: Log Into Your Microsoft Account.
.png)
Command 0: Set-ExecutionPolicy RemoteSigned
Command 1: Install-Module -Name ExchangeOnlineManagement
Command 2: Import-Module ExchangeOnlineManagement
.png)
Please note that if you are importing the ExchangeOnlineManagement for the first time it will take a few moments to load in. If you have already installed ExchangeOnlineManagement in the past you will still need to import this.
Once you enter in the 2nd command it will prompt you to sign in using this email address and password. Once you have successfully logged in, you will be greeted by this message.
.png)
Step 3: Enable your SMTP Authentication.
It will take a few moments to process but once a new line starts with no error message than it was success.
.png)
Step 4: Add Your Inbox To Warmup Inbox.
Email Provider: Other
SMTP Password: Your Password
SMTP Host: smtp.office365.com
SMTP Port: 587
Use SMTP SSL/TLS: Disabled
IMAP Password: Your Password
IMAP Host: outlook.office365.com
IMAP Port: 993
Use IMAP SSL/TLS: Enabled
For IMAP
Step 1: Launch Powershell In Administrator Mode

Step 2: Log Into Your Microsoft Account.
Command 1: Install-Module -Name ExchangeOnlineManagement
Command 2: Import-Module ExchangeOnlineManagement
.png)
Please note that if you are importing the ExchangeOnlineManagement for the first time it will take a few moments to load in. If you have already installed ExchangeOnlineManagement in the past you will still need to import this.
Once you enter in the 2nd command it will prompt you to sign in using this email address and password. Once you have successfully logged in, you will be greeted by this message.
.png)
Step 3: Enable IMAP
.png)
It will take a few moments to process but once a new line starts with no error message than it was success.
I’m trying to write a script in PS to fetch all unseen/unread messages via imap and import them into a SQL-DB. After the import I want to set the message as seen and move it to a subfolder. Everything works fine, execpt I can’t figure out, how to set a message as read.
Below is my script
Add-Type -Path "$PSScriptRoot\MailKit.dll" Add-Type -Path "$PSScriptRoot\MimeKit.dll" $Mail_Server = '***' $Mail_Port = '***' $Mail_Username = '***' $Mail_Password = '***' $Imap_Client = New-Object MailKit.Net.Imap.ImapClient $Imap_Client.Connect($Mail_Server,$Mail_Port) $Imap_Client.Authenticate($Mail_Username,$Mail_Password) $Imap_Client.Inbox.Open([MailKit.FolderAccess]::ReadWrite) | Out-Null $Root_Folder = $Imap_Client.GetFolder($Imap_Client.PersonalNamespaces[0]) $Inbox_Folder = $Root_Folder.GetSubfolder("INBOX") $Archive_Folder = $Inbox_Folder.GetSubfolder("Archiv") $Mail_UIDs = $Imap_Client.Inbox.Search([MailKit.Search.SearchQuery]::AND([MailKit.Search.SearchQuery]::NotSeen,[MailKit.Search.SearchQuery]::New)) if($Mail_UIDs.Count -gt 0) { ForEach($UID in $Mail_UIDs.GetEnumerator()) { #do stuff $Inbox_Folder.AddFlags($UID,([MailKit.MessageFlags]::Seen)) #not working $Imap_Client.Inbox.MoveTo($UID,$Archive_Folder) | Out-Null #works } }
$Imap_Client.Disconnect($true) asked Sep 20, 2023 at 11:15
As you say, there have been changes in MailKit recently and most of the examples you will find are referring to the old (and now removed) .addflags method.
You are right about store being the correct interface, but you were still trying to use it like the old method, while it needs a StoreFlagRequest being passed a StoreAction and a MessageFlag :
$Inbox_Folder.Store($UID, [MailKit.StoreFlagsRequest]::new([MailKit.StoreAction]::Add,[MailKit.MessageFlags]::Seen))or, (since Powershell will try cast the string to the corret types anyways), in a simpler way:
$Inbox_Folder.Store($UID, [MailKit.StoreFlagsRequest]::new("Add","Seen"))the updated docs are (I’ve just tried googling that) the only updated reference at the time of writing:
1 gold badge4 silver badges14 bronze badges
I have tried this script:
Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook"
# Prompt the user for input
$emailAddress = Read-Host "Enter your email address"
$smtpServer = Read-Host "Enter the SMTP server address (default: smtp.example.com)"
$imapServer = Read-Host "Enter the IMAP server address (default: imap.example.com)"
$password = Read-Host "Enter your password" -AsSecureString
# Set default server values if not provided
if ([string]::IsNullOrEmpty($smtpServer)) { $smtpServer = "smtp.example.com"
}
if ([string]::IsNullOrEmpty($imapServer)) { $imapServer = "imap.example.com"
}
# Create a new Outlook Application object
$outlook = New-Object -ComObject Outlook.Application
# Create a new NameSpace object
$namespace = $outlook.GetNamespace("MAPI")
# Get the Outlook Accounts collection
$accounts = $namespace.Accounts
# Set the properties of the Account object
$mailAccount = $namespace.Accounts.Add("$emailAddress", "IMAP/SMTP", $imapServer, $smtpServer)
$mailAccount.SmtpUser = $emailAddress
$mailAccount.SmtpPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
$mailAccount.SendAndReceiveEnabled = $true
$mailAccount.Save()
# Display a confirmation message
Write-Host "Outlook account has been created with the provided information."- $mailAccount = $namespace.Accounts.Add(“$emailAddress”, “IMAP/SMTP”, …
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
- $mailAccount.SmtpUser = $emailAddress
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
The property ‘SmtpPassword’ cannot be found on this object. Verify that the property exists and can be set.
At line:29 char:1
- $mailAccount.SmtpPassword = [System.Runtime.InteropServices.Marshal]: …
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
The property ‘SendAndReceiveEnabled’ cannot be found on this object. Verify that the property exists and can be set.
At line:30 char:1
- $mailAccount.SendAndReceiveEnabled = $true
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At line:31 char:1
- $mailAccount.Save()
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull




