保存带有传入电子邮件发件人姓名或电子邮件地址的附件 [英] Save attachment with incoming email sender's name or email address
问题描述
我想通过将每个传入电子邮件的发件人名称添加到保存的附件项中,方法是将其存储到变量中,以便以后使用,以将电子邮件返回该名称或电子邮件地址.
I want to add the sender's name of every incoming email to the saved attachment item, by storing into a variable so I can use it later, to return the email to that name or email address.
以下代码首先为文件夹中的每个项目创建一个计数器,然后使用以下日期和原始附件重命名该文件:"2016-01-29 1026 1 POCreation"-"POCreation"之前的数字1为柜台.
The code below first creates a counter for every item on a folder and rename the file with the date and the original attachment as follows: "2016-01-29 1026 1 POCreation" - the number 1 before the "POCreation" is the counter.
然后,我通过在Outlook中运行规则以在脚本以下运行(如您所知)来保存附件,并使用objAtt.DisplayName保存附件名称
Then I save the attachment by running a rule in Outlook to run below script - as you might be aware - and save the attachment name by using the objAtt.DisplayName
因此,基本上,我想获取发件人的姓名或发件人的电子邮件,并将其存储在变量中.我访问过的所有论坛(甚至在这里)都解释说,它们转到了"MAPI 文件夹以读取其中的所有电子邮件,但我认为也许可以像使用.displayname一样直接整理邮件.
So basically I want to get the name of the sender or the email of the sender stored on a variable. All the forums that I visit, even here, explained that they go to the "MAPI" folder to read all the emails in there but I am thinking that perhaps I can get it straight just like using the .displayname.
我尝试使用mailitem.sendername,但这引发了未找到对象的错误,我想不是从传入电子邮件中读取它.我正在将其运行到Outlook模块中.
I tried to use mailitem.sendername but this throws an error of object not found, I guess is not reading it from the incoming email. I am running this into a module of 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
推荐答案
您可以使用MailItem类的以下属性:
You can use the following properties of the MailItem class:
- SenderEmailAddress -表示电子邮件的字符串Outlook项目发件人的地址.
- SenderName -一个字符串,指示Outlook项目的发送者.
- SenderEmailAddress - a string that represents the e-mail address of the sender of the Outlook item.
- SenderName - a string indicating the display name of the sender for the Outlook item.
请参见如何:获取邮件发件人的SMTP地址项目以获取更多信息.
See How to: Get the SMTP Address of the Sender of a Mail Item for more information.
这篇关于保存带有传入电子邮件发件人姓名或电子邮件地址的附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!