メインコンテンツへスキップ

Kutools for Office — 1つのスイート、5つのツールで、もっと多くのことを成し遂げましょう。

Outlookで1通または複数のメールから送信者のメールアドレスを取得するにはどうすればよいですか?

Author Siluvia Last modified

Outlookで受信した1通または複数のメールの「差出人」フィールドからメールアドレスを抽出しようとしたことはありますか?この記事では、このタスクを支援するためのVBAコードを提供します。


Outlookで1通または複数のメールから送信者のメールアドレスを取得する

次のVBAコードを実行して、Outlookで受信した1通または複数のメールの「差出人」フィールドからメールアドレスを抽出してください。

1. メールフォルダを開き、送信者のメールアドレスを取得したいメールを選択します。Alt + F11キーを押して、Microsoft Visual Basic for Applicationsウィンドウを開きます。

注意: 複数のメールを選択するには、Ctrlキーを押しながらメールを1つずつ選択してください。

2. Microsoft Visual Basic for Applicationsウィンドウで、挿入 > モジュールをクリックし、次のVBAコードをモジュール(コード)ウィンドウにコピーします。

steps on getting the sender’s email address from one or more emails in Outlook

VBAコード:Outlookで1通または複数のメールから送信者のメールアドレスを抽出する

Sub GetSmtpAddressOfSelectionEmail()
  Dim xExplorer As Explorer
  Dim xSelection As Selection
  Dim xItem As Object
  Dim xMail As MailItem
  Dim xAddress As String
  Dim xFldObj As Object
  Dim FilePath As String
  Dim xFSO As Scripting.FileSystemObject
  On Error Resume Next
  Set xExplorer = Application.ActiveExplorer
  Set xSelection = xExplorer.Selection
  For Each xItem In xSelection
    If xItem.Class = olMail Then
      Set xMail = xItem
      xAddress = xAddress & VBA.vbCrLf & "  " & GetSmtpAddress(xMail)
    End If
  Next
  If MsgBox("Sender SMTP Address is: " & xAddress & vbCrLf & vbCrLf & "Do you want to export the address list to a txt file? ", vbYesNo, "Kutools for Outlook") = vbYes Then
    Set xFldObj = CreateObject("Shell.Application").BrowseforFolder(0, "Select a Folder", 0, 16)
    Set xFSO = New Scripting.FileSystemObject
    If xFldObj Is Nothing Then Exit Sub
    FilePath = xFldObj.Items.Item.Path & "\Address.txt"
    Close #1
    Open FilePath For Output As #1
    Print #1, "Sender SMTP Address is: " & xAddress
    Close #1
    Set xFSO = Nothing
    Set xFldObj = Nothing
    MsgBox "Address list has been exported to:" & FilePath, vbOKOnly + vbInformation, "Kutools for Outlook"
  End If
End Sub
Function GetSmtpAddress(Mail As MailItem)
  Dim xNameSpace As Outlook.NameSpace
  Dim xEntryID As String
  Dim xAddressEntry As AddressEntry
  Dim PR_SENT_REPRESENTING_ENTRYID As String
  Dim PR_SMTP_ADDRESS As String
  Dim xExchangeUser As exchangeUser
  On Error Resume Next
  GetSmtpAddress = ""
  Set xNameSpace = Application.Session
  If Mail.sender.Type <> "EX" Then
    GetSmtpAddress = Mail.sender.Address
  Else
    PR_SENT_REPRESENTING_ENTRYID = "http://schemas.microsoft.com/mapi/proptag/0x00410102"
    xEntryID = Mail.PropertyAccessor.BinaryToString(Mail.PropertyAccessor.GetProperty(PR_SENT_REPRESENTING_ENTRYID))
    Set xAddressEntry = xNameSpace.GetAddressEntryFromID(xEntryID)
    If xAddressEntry Is Nothing Then Exit Function
    If xAddressEntry.AddressEntryUserType = olExchangeUserAddressEntry Or xAddressEntry.AddressEntryUserType = olExchangeRemoteUserAddressEntry Then
      Set xExchangeUser = xAddressEntry.GetExchangeUser()
      If xExchangeUser Is Nothing Then Exit Function
      GetSmtpAddress = xExchangeUser.PrimarySmtpAddress
    Else
      PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
      GetSmtpAddress = xAddressEntry.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS)
    End If
  End If
End Function

3. ツール > 参照設定をクリックし、 参照設定 – Project1ダイアログボックスで Microsoft Scripting Runtimeのチェックボックスをオンにします。

steps on getting the sender’s email address from one or more emails in Outlook

4. F5キーを押してコードを実行します。すると、Kutools for Outlookダイアログボックスが表示され、選択されたメールのすべての送信者のメールアドレスがリストアップされます。

注意:

アドレスリストをtxtファイルにエクスポートする必要がある場合は、はいボタンをクリックしてください。
または、いいえボタンをクリックして処理を終了します。
steps on getting the sender’s email address from one or more emails in Outlook

5. はいボタンをクリックすると、フォルダー参照ダイアログボックスが表示されます。ファイルを保存するフォルダーを選択し、OKボタンをクリックしてください。

steps on getting the sender’s email address from one or more emails in Outlook

6. 最後に、Kutools for Outlookダイアログボックスが表示され、エクスポートされたファイルのパスが通知されます。OKをクリックして閉じます。

steps on getting the sender’s email address from one or more emails in Outlook

7. エクスポートされたファイルが保存されているフォルダーに移動し、Addressという名前の.txtファイルを開いて、選択されたメールの送信者のメールアドレスを確認します。

steps on getting the sender’s email address from one or more emails in Outlook

最高のオフィス生産性ツール

最新情報: Kutools for Outlook 無料版リリース!

新しくなった Kutools for Outlook を100以上の素晴らしい機能とともに体験してください!今すぐダウンロードしてみましょう!

🤖 Kutools AI : 高度なAI技術を活用し、メールの返信、要約、最適化、拡張、翻訳、作成までを簡単に処理します。

📧 メール自動化: 自動返信(POPとIMAPに対応) / スケジュール電子メールを送信 /送信時にルールで自動 CC/BCC / 高度なルールによる自動転送 / 挨拶を自動追加 / 複数宛先メールを自動的に一通ずつ分割...

📨 メール管理: メールの取り消し / 件名などで詐欺メールをブロックする / 重複メールを削除 / 高度な検索 / フォルダーを整理...

📁 添付ファイルプロ: 一括保存 / 一括切り離し / 一括圧縮 / 自動保存 / 自動的に切り離す / 自動圧縮...

🌟 インターフェイスマジック: 😊さらに美しくてクールな絵文字 /重要なメール到着時に通知 / Outlookを閉じるのではなくグループを最小化...

👍 ワンクリック便利機能: 全員に【Attachment】付きで返信 / フィッシング対策メール / 🕘送信者のタイムゾーン表示...

👩🏼‍🤝‍👩🏻 連絡先&カレンダー: 選択したメールから一括で連絡先を追加 /連絡先グループを個別グループに分割 / 誕生日のリマインダーを削除...

お好みの言語で Kutools を利用可能 ― 英語、スペイン語、ドイツ語、フランス語、中国語など40以上の言語に対応!

Kutools for Outlookをワンクリックですぐに利用開始。待たずに今すぐダウンロードして効率を高めましょう!

kutools for outlook features1 kutools for outlook features2

🚀 ワンクリックダウンロード — Office用アドインをすべて入手

強くおすすめ: Kutools for Office(5-in-1)

ワンクリックで五つのインストーラーを同時ダウンロード ― Kutools for Excel、Outlook、Word、PowerPointOffice Tab Pro 今すぐダウンロード!

  • ワンクリックの便利さ: 五つのセットアップパッケージを一度にダウンロードできます。
  • 🚀 あらゆるOffice作業に準備完了: 必要なアドインをいつでもインストール可能です。
  • 🧰 含まれるもの: Kutools for Excel / Kutools for Outlook / Kutools for Word / Office Tab Pro / Kutools for PowerPoint