Failed to send email from search box in powershell

I have a powershell script that searches Windows search index directly for emails and files. I have the following code:

$searchme="my thing to find"
$sql="SELECT System.FileName, System.ItemPathDisplay, System.DateCreated, System.DateModified, system.itemurl, system.itemtypetext FROM SYSTEMINDEX WHERE Contains(System.FileName, '"+$searchme+"') OR Contains('"+$searchme+"')"
$adapter = new-object system.data.oledb.oleDBDataadapter -argumentlist $sql, "Provider=Search.CollatorDSO;Extended Properties=’Application=Windows’;"
$ds      = new-object system.data.dataset
$adapter.Fill($ds)
foreach ($record in $ds.Tables[0].Rows)
{
    $exeparams = $record[4]
    write-host $exeparams
    write-host $exeparams.split(":")[0]
    if ($exeparams.split(":")[0] -eq "mapi15")
    {
        $exeparams2="mapi://" + $exeparams.substring(8)
    }
    write-host $exeparams
    write-host "start"
    $exe="start"
    $exe+" "+$exeparams | Out-File 'file.txt' -encoding Unicode
    write-host "start-process"
    Start-Process $exeparams
    Start-Process $exeparams2
    write-host "andpersand process"
    &$exe $exeparams
    &$exe $exeparams2
    write-host "dotnet"
    $proc = [Diagnostics.Process]::Start($exeparams)
    $proc.WaitForExit()
    $proc = [Diagnostics.Process]::Start($exeparams2)
    $proc.WaitForExit()
}

      

There are several "shell" calls because I was trying to figure out if it was a process spawning issue. The files work without problems. However, the error messages don't have any such interface if I leave mapi15 or Unspecified error if I change mapi15 to mapi. I believe that Opening emails in Outlook from java using "mapi: //" protocol might be a solution, but if it's not me, then I'm not sure how to apply this in powershell. Thank you for your help.

+3


source to share


1 answer


Ok, it took more work than I expected and I blame Office 2013 for that. Here's a short answer:

$exeparams2 = $exeparams -replace "^mapi15", "mapi"
& start $exeparams2

      

This is the code that now opens my email. This code didn't do it yesterday, all it did was tell me:

Either there is no default mail client, or the current mail client cannot fulfill the messaging request. Start Microsoft Outlook and set it as your default email client.

The worry is what it was because I had Outlook, it actually worked, and was the default mail application for everything email related. This annoyed me and sent me on a quest to find out that WTF is wrong and if I could fix it. The answers to this are "I'm not sure if the WTF was wrong, except perhaps changing the names in the MS part" and "yes, yes, I can fix that."

I finally found a fix that worked for me (and , I believe it's probably Office 2013 / Office 365, ) was found at the bottom of this thread:



https://social.technet.microsoft.com/Forums/office/en-US/64c0bedf-2bcd-40aa-bb9c-ad5de20c84be/cannot-send-email-with-microsoft-outlook-2010-64-bit-from- adobe-outlook-not-recognized-as? forum = outlook

The process is simple. Modify 2 registry entries, then re-configure the default mail application. Registry entries:

HKLM: \ Software \ Clients \ Mail (default)
HKLM: \ Software \ Clients \ Mail \ Microsoft Outlook (default)

Change the value (Default)

in "Microsoft Outlook" to just "Outlook".

After that, I set Outlook as default for everything that might be (in Win8, that Control Panel> All Control Panel Items> Default Programs> Set Default Programs, then select Outlook and select the first option to make it the default for everyone which he registered). Once that was done, I was able to run the modified code above to launch the email I was looking for the index.

+2


source







All Articles