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

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

Author: Siluvia Last Modified: 2025-05-23

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 の無料版を体験してください。70以上の素晴らしい機能が永遠に使えます!今すぐダウンロードをクリック!

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

📧 メール自動化: 自動返信 (POPとIMAPで利用可能) / メール送信のスケジュール / メール送信時にルールによる自動 CC/BCC / 自動転送 (高度なルール) / 自動挨拶追加 / 複数の宛先を持つメールを個別のメールに自動的に分割...

📨 メール管理: メールの取り消し / 件名やその他によるスパムメールのブロック / 重複したメールの削除 / 高度な検索 / フォルダーを整理...

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

🌟 インターフェースマジック: 😊より美しくクールな絵文字 /重要なメールが来たときに通知 / クローズ中ではなくOutlookを最小化...

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

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

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

kutools for outlook features1 kutools for outlook features2