a_sue’s diary

a_sue の日記 はてなブログ版

Microsoft Outlook 2007の送信メールを自動的にEvernoteに登録する

完全にEvernoteにはまってます。初めて導入して、数日後には有償のプレミアムに変更してました。
印刷からEvernoteに突っ込む方法も、PDFCreaterPDFCreatorを使う方法を知り、解決。
http://r.nanapi.jp/1768/
ありがとうございます。
あとは、Outlook 2007のメールを自動的に取り込めるといいのだけど、残念ながらEvernoteは自動仕分けツールで利用できるカスタムアクションになってません。じゃあどうするかということで、着信や送信のタイミングでスクリプトを実行する方法に挑戦。
参考にしたのはここら辺。

PDFCreaterの設定でも使われてますが、Windows版をインストールすると一緒にインストールされるENScript.exeを使うと、テキストファイルを自由に突っ込める様子。

Usage: ENScript createNote [options]

Options:

/s file - file containing the plain text note contents. If omitted, note contents are read from standard input.
/n notebook - notebook to create the note in. If does not exist, lazy create.If omitted, use default notebook.
/i title - specifies note title. If omitted, note title will be generated automatically.
/t tag - specifies note tag. If tag does not exist, lazy create it. Use multiple /t options to specify multiple tags.
/a filename - specifies file attachment. Use multiple /a options to specify multiple file attachments.
/c dttm - note creation date/time. { "YYYY/MM/DD hh:mm:ss" | filetime }. If omitted, use current time.
/u username - user name if not the same as database file name.
/p password - user password to confirm Evernote service access.
/d database - database file name if user name is not specified.

If both database file name and user name are not specified, last login name is used and
if there is none, USERNAME environment variable value is used as a user name.

Alt+F11でVisual Basic Editorを開き、下記コードを貼れるようにするのにちょっとじたばたしちゃって、実はどうやるのがいいのか、今ここではっきり示せません。とりあえず下記コードを貼ってMsgBoxで動きを確認しながら手探りで動かしていきました。
貼るのは、[Project1]-[Microsoft Office Outlook Objects]-[ThisOutlookSession]です。ツリーを展開していって、[ThisOutlookSession]をダブルクリックすると、貼れる画面が開きます。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim strENpath, strENS
    Dim oMail As MailItem
    Dim myDate As Date
    Dim myTime
    Dim strOutfile As String
    
    Set oMail = Item
    myDate = Date + Time
    
    ' テンポラリのファイル名をつくる
    strOutfile = Environ("tmp") & "\myENO" & Format(myDate, "YYYYMMDDhhmmss") & ".txt"
    
    ' メールを出力
    Open strOutfile For Output As #1
'    Print #1, "From: "; oMail.SenderName   'うまくいかない?
    Print #1, "Sent: "; Format(myDate, "YYYY/MM/DD(aaa) hh:mm:ss")
    Print #1, "To: "; oMail.To
    Print #1, "CC: "; oMail.CC
    Print #1, "BCC: "; oMail.BCC
    Print #1, "Subject: "; oMail.Subject
    Print #1, ""
    Print #1, oMail.Body
    Close #1
    
    strENpath = """C:\Program Files\Evernote\Evernote3.5\ENScript.exe"" createNote"
'    strENS = strENpath & " /s """ & strOutfile & """ /i """ & oMail.Subject & """ /c """ & Format(myDate, "YYYY/MM/DD hh:mm:ss") & """ /n テスト "
    strENS = strENpath & " /s """ & strOutfile & """ /i """ & oMail.Subject & """ /c filetime /n 送信メール"
    
'   MsgBox "EverNote: " & strENS
    
   ' ENScript を呼び出して登録
   Dim rtn
   rtn = Shell(strENS)

    ' テンポラリの後始末をしてません
End Sub

テンポラリファイルの後始末をしてません。実はセキュリティ上まずいかも。また、署名のないスクリプトも実行するように設定しないと動きません。
いろいろ問題があるので、もし使うなら自己責任でお願いします。
これだけの情報で動かすことができなかったら、多分使わない方がいいです。

->自動的にBCCに追加して送り込む方法