0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

右クリック→送る→「メール受信者」を削除してしまった場合の対処

Last updated at Posted at 2021-12-08

職場のPCの「送る」メニューに色々と邪魔なものがあったので整理していたところ、「メール受信者」を削除してしまいました。修復方法を検索してみると「他ユーザーのSendToフォルダから拾ってくれば問題ない」という情報は見つかりましたが、今回は他ユーザーのSendToにあったものも削除してしまい、どうやら自PCのみでは修復不能な状況に。

というわけでそんな感じの動きをするスクリプトを書いてみました。

用意したもの
・mail.bat
・mail.ps1

mail.bat
@echo off
pushd %~dp0

if not "%X_MIMIMIZED%"=="1" (
    set X_MIMIMIZED=1
    start /min cmd /c,"%~0" %*
    exit
)
powershell -NoProfile -ExecutionPolicy RemoteSigned .\mail.ps1 %1
popd
mail.ps1
Param($filename)
$ret = $filename -match ".*\\(.*?)$"

$To = ""
$CC = ""
$Subject = "$filename"
$Body = ""

function CreateMailByOutlook {
	$outlookProcess = Get-Process -Name "OUTLOOK" -ErrorAction SilentlyContinue
    $needQuit = $false
    if ($outlookProcess -eq $null) {
        $needQuit = $true
    }
    $Outlook = New-Object -ComObject Outlook.Application
    $namespace = $outlook.GetNamespace("MAPI")
    $Mail = $Outlook.CreateItem(0)
    $Mail.To = $To
    $Mail.CC = $CC
    $Mail.Subject = $matches[1]
    $Mail.Body = $Body
    $attachments = $mail.Attachments
    $addResult = $attachments.Add($filename)
    $inspector = $Mail.GetInspector
    $inspector.Display()

	if ($needQuit) {
            [void]$outlook.Quit()
            [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($outlook)
        }
}

function Main {
    CreateMailByOutlook
}

Main

これらを適当なフォルダに置いておき、mail.batファイルへのショートカットをSendToに置いてみました。

・実行結果

sendto.png

04.png
cmdが動いているのが少し見えるので見た目が少しよろしくありませんが、やりたかった感じのことはできているみたいです。右クリックからメールを送ろうとしたときの「電子メールで送信: 」などの自動で入ってくる余計な文字列が邪魔だったので、その辺も自分で設定できるのは少し便利な感じはします。

スクリプトを作る方向でやってみましたが、このスクリプトではOutlook以外のメーラーを使っている場合には全く役に立たないという問題が残るので、通常の『メール受信者』を取り戻す方法も調べてみました。

そもそもこれってどういうファイルなんだろうと確認してみると、こんな感じのファイルみたいです。

02.png
03.png
どうやらファイル実体は「Mail Recipient.MAPIMail」という名前みたいです。テキストエディタで開いてみると中身は「Mail」とだけ書いてありました。

試しに自PCで「Mail Recipient.MAPIMail」(空白ファイル)を作成してみると『メール受信者』と全く同じ動作をするファイルになりました。

05.png
(同じファイルを添付したのに上のやり方と添付ファイルのサイズが違うのはなんでなんだろう…?)

参考:
【PowerShell】Outlookを操作する
https://qiita.com/vicugna-pacos/items/b0f94c590f018c7e0d16

RedmineをあきらめたオレたちのPowerShellでのOutlookの自動操作
https://qiita.com/mima_ita/items/37ab711a571f29346830

追記:PowerShellを最新版にバージョンアップしたところ、メール送信したいファイルのパスに半角スペースが含まれている場合にうまく動かなくなりました。
mail.batファイルのPowerShellをコールしている行を1行修正したら動きました。

mail.bat
@echo off
pushd %~dp0

if not "%X_MIMIMIZED%"=="1" (
    set X_MIMIMIZED=1
    start /min cmd /c,"%~0" %*
    exit
)
powershell -NoProfile -ExecutionPolicy RemoteSigned .\mail.ps1 \"%~1\"
popd
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?