所以我有一个访问程序,允许用户选择要导入到表的outlook文件夹。然后可以从组合框中选择并转移到表格中使用。
但是我遇到的问题是我要返回的其中一个值。 SenderEmailAddress实际上并没有给我一个电子邮件地址,例如这就是我在表格中保存的内容。
我删除了隐私名称。
/O=COMPANY/OU=MAIL12/CN=RECIPIENTS/CN=FIRSTNAME.LASTNAME
当然,如果我想将此值传回Outlook以回复电子邮件,我无法使用此功能。
有人可以帮帮我吗?
Public Sub LoadEmails()
On Error Resume Next
'Outlook wasn't running, start it from code
If Started = False Then
Set olApp = New Outlook.Application '("Outlook.Application")
Started = True
End If
Set myNamespace = olApp.GetNamespace("MAPI")
Set objFolder = myNamespace.PickFolder
' if outlook is closed, it will display this error
If Err <> 0 Then
MsgBox "Outlook was closed. Please log out and log back in."
Started = False
Exit Sub
End If
'Exit if no folder picked.
If (objFolder Is Nothing) Then
MsgBox "No Folder Selected"
Started = False
Exit Sub
End If
Dim adoRS As Recordset
Dim intCounter As Integer
Set adoRS = CurrentDb.OpenRecordset("TBL_UserInbox") 'Open table Inbox
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
If .Class = olMail Then
adoRS.AddNew
adoRS("Subject") = .Subject
adoRS("TimeReceived") = .ReceivedTime
adoRS("Body") = .Body
adoRS("FromName") = .SenderEmailAddress '<<< Issue
adoRS("ToName") = .To
adoRS.Update
End If
End With
Next
MsgBox "Completed"
Started = False
End Sub
答案 0 :(得分:3)
这是EX类型的完全有效的电子邮件地址(与SMTP相对)。检查MailItem.SenderEmailType属性。如果是&#34; SMTP&#34;,请使用SenderEmailAddress属性。如果是&#34; EX&#34;,请使用MailItem.Sender.GetExchangeUser.PrimarySmtpAddress。准备好处理空值/例外。