获取发件人的电子邮件地址 [英] Get Email Address of Sender

查看:385
本文介绍了获取发件人的电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我希望我在正确的地方:P



i am尝试从Outlook电子邮件中提取发件人的电子邮件地址。我得到了这段代码并进行了一些修改以允许用户选择代码应该进入的文件夹。





Hi Everyone,

I Hope i'm on the right place :P

i am trying to extract the email address of sender from an outlook email. i got this piece of code and modified a little to allow a user select what folder should the code run into.


Sub GetSMTPaddress()
     
    Dim ns As NameSpace
    Dim fldr As MAPIFolder
    Dim m As MailItem
    Dim xlApp As Object
    Dim xlWB As Object
    Dim xlSht As Object
    Dim r As Long
     
     'set up an Excel sheet for the results
    Set xlApp = CreateObject("Excel.Application")
    Set xlWB = xlApp.Workbooks.Add
    Set xlSht = xlWB.Sheets.Add
    xlSht.Name = "SMTPs"
     
     'target the selected folder
    Set ns = Application.GetNamespace("MAPI")
   Set fldr = ns.GetFolderFromID( _
ActiveExplorer.CurrentFolder.EntryID, _
ActiveExplorer.CurrentFolder.StoreID)

     
    r = 1 'used as excel row index
    For Each m In fldr.Items 'loop thru the mail items
        If m.SenderEmailType = "SMTP" Then
             'check it's not already in col A of our results sheet
            If xlSht.Columns(1).Find(m.SenderEmailAddress, LookIn:=xlValues) Is Nothing Then
                xlSht.Cells(r, 1).Value = m.SenderEmailAddress
                r = r + 1 'increment the row index counter
                msg = m.Subject
            End If
        End If
    Next m
     
     'show the results
    xlApp.Visible = True
     
End Sub





i在我的outlook上创建了一个虚拟文件夹来测试结果。我使用我的另一封电子邮件向我的Outlook帐户发送了一封电子邮件。使用至少2个电子邮件地址将测试电子邮件发送到我的Outlook电子邮件。



我选择了该文件夹。然后运行脚本。

当我运行代码时,Excel文件应该在行中显示2个不同的电子邮件地址。



Excel不会t填充所选文件夹中的电子邮件。我检查了Outlook的VBA窗口并测试了脚本,如果脚本选择了正确的文件夹,那么它能够。





i created a dummy folder on my outlook to test the result. i sent an email to my outlook account using another email of mine. used at least 2 email addresses to send test emails to my outlook email.

i selected the folder. then run the script.
well the Excel file should show 2 different email address in rows when i run the code.

Excel doesn't populate the emails from the selected folder. i checked the VBA window of outlook and tested the script if the correct folder is selected by the script and Yes it was able to.

The

Dim m As MailItem

甚至显示第一个测试邮件的主题行。







请告诉我代码出错的地方?在此先感谢。

even shows the subject line of the first test mail.



Please let me know where the code went wrong? Thanks in advance.

推荐答案

您好,



您必须定义xlValues



在代码顶部添加:

Hello,

You have to define xlValues

Add at the top of your code:
Const xlValues = -4163





您可以在此处找到Excel常量的完整列表:

http://www.datapigtechnologies.com/downloads/Excel_Enumerations.txt [ ^ ]







Valery。



You can find a comprehensive list of Excel constants here:
http://www.datapigtechnologies.com/downloads/Excel_Enumerations.txt[^]



Valery.


这篇关于获取发件人的电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆