首页 文章

使用收到的电子邮件发件人姓名或电子邮件地址保存附件

提问于
浏览
0

我想将每个传入电子邮件的发件人姓名添加到已保存的附件项中,方法是存储到变量中以便稍后使用,以便将电子邮件返回到该名称或电子邮件地址 .

下面的代码首先为文件夹中的每个项目创建一个计数器,并使用日期和原始附件重命名该文件,如下所示:“2016-01-29 1026 1 POCreation” - “POCreation”之前的数字1是计数器 .

然后我通过在Outlook中运行规则来保存附件以在脚本下运行 - 您可能知道 - 并使用objAtt.DisplayName保存附件名称

So basically I want to get the name of the sender or the email of the sender stored on a variable. 我访问的所有论坛,甚至在这里,解释说他们去"MAPI"文件夹阅读那里的所有电子邮件,但我想也许我可以直接就像使用.displayname一样 .

我试图使用mailitem.sendername,但这会抛出一个找不到对象的错误,我猜不是从收到的邮件中读取它 . 我将它运行到Outlook的模块中 .

Public Sub pdf(itm As Outlook.MailItem)
Dim FolderPath As String, path As String, count As Integer
FolderPath = "C:\Users\esacahui\Documents\POS\received"

path = FolderPath & "\*.xlsm"

FileName = Dir(path)

Do While FileName <> ""
    count = count + 1
    FileName = Dir()
Loop
' that was the counter, now is the save attachment 

Dim objAtt As Outlook.Attachment
Dim saveFolder As String
    saveFolder = "C:\Users\esacahui\Documents\POS\received"
Dim dateFormat As String
    dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd Hmm")

For Each objAtt In itm.Attachments
    objAtt.SaveAsFile saveFolder & "\" & dateFormat & " " & count & " " & objAtt.DisplayName
Next

End Sub

2 回答

  • 0

    itm.senderEmailAddress将为您提供发件人的电子邮件地址 .

  • 0

    您可以使用MailItem类的以下属性:

    • SenderEmailAddress - 表示Outlook项目发件人的电子邮件地址的字符串 .

    • SenderName - 一个字符串,指示Outlook项目的发件人的显示名称 .

    有关更多信息,请参阅How to: Get the SMTP Address of the Sender of a Mail Item .

相关问题