Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / October 2005

Tip: Looking for answers? Try searching our database.

Obtaining SMTP headers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Howard Kaikow - 27 Oct 2005 19:51 GMT
I modified the code in MSFT KB article 194870 to choose all messages. I give
the code below.
I placed the code in a class and added a macro to call the code.

However, this causes two messages to appear:

1. AA mesage to select the Profile to be used. This occurs once.
2. The message caused by Outlook SEcurity that could be bypassed if I were
using the EntryID. This occurs for each message.

How can I avoid these messages?

   Dim oSession As MAPI.Session
   Dim oFolder As Folder
   Dim oMsgColl As Messages
   Dim oMessage As Message

   ' Logon to the MAPI session
   Set oSession = New MAPI.Session
   oSession.Logon

   ' Get the Inbox folder and its message collection.
   Set oFolder = oSession.GetDefaultFolder(CdoDefaultFolderInbox)
   Set oMsgColl = oFolder.Messages

   ' Search through the messages in the Inbox for the Internet
   ' message.  Then use the CdoPR_TRANSPORT_MESSAGE_HEADERS
   ' (&H7D001E) property tag to retrieve the Internet header.
   ' If the property doesn't exist(Not a Internet message) you will
   ' receive a MAPI_E_NOT_FOUND error.

   For Each oMessage In oMsgColl
' My modification is the removal of the If and the addition of the On Error
       On Error Resume Next
       MsgBox oMessage.Fields(&H7D001E) 'Display the header
       Err.Clear
   Next

   ' Logoff and cleanup
   oSession.Logoff
   Set oSession = Nothing
   Set oMessage = Nothing
   Set oMsgColl = Nothing
   Set oFolder = Nothing

Signature

http://www.standards.com/; See Howard Kaikow's web site.

Dan Mitchell - 27 Oct 2005 21:35 GMT
> 1. AA mesage to select the Profile to be used. This occurs once.

That's because you're calling oSession.Logon and not passing in the name
of a profile to use. See the docs for more, but what you probably want to
do is set newSession to 'false' (rather than the default of true) so it'll
use your existing Outlook session.

> 2. The message caused by Outlook SEcurity that could be bypassed if I
> were using the EntryID. This occurs for each message.

See http://www.outlookcode.com/d/sec.htm

-- dan
Howard Kaikow - 27 Oct 2005 23:05 GMT
> > 1. AA mesage to select the Profile to be used. This occurs once.
>
>  That's because you're calling oSession.Logon and not passing in the name
> of a profile to use. See the docs for more, but what you probably want to
> do is set newSession to 'false' (rather than the default of true) so it'll
> use your existing Outlook session.

Thanx.
I just figured that one out.

> > 2. The message caused by Outlook SEcurity that could be bypassed if I
> > were using the EntryID. This occurs for each message.
>
>  See http://www.outlookcode.com/d/sec.htm

I've seen that.

I am using code in a Run As Script with EntryID.
My problem is modifying that to grab the headers.
Dmitry Streblechenko - 27 Oct 2005 21:38 GMT
1. If you are using that code along with Outlook 2002 or higher, replace the
line
oSession.Logon
with
oSession.MAPIOBJECT = Namespace.MAPIOBJECT

2. See http://www.outlookcode.com/d/sec.htm

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

>I modified the code in MSFT KB article 194870 to choose all messages. I
>give
[quoted text clipped - 42 lines]
>    Set oMsgColl = Nothing
>    Set oFolder = Nothing
Howard Kaikow - 27 Oct 2005 23:24 GMT
Thanx.

I am currently using the code below in a rule.

Is there some way to use olMail to access the headers and avoid the security
warnings?

Public Sub ProcessRulesList(objMsg As Outlook.MailItem)
   Dim intFile As Integer
   Dim objFields As MAPI.Fields
   Dim objItems As Outlook.ItemProperties
   Dim objItem As Outlook.ItemProperty
   Dim objMessage As MAPI.Message
   Dim olNS As Outlook.NameSpace
   Dim olMail As Outlook.MailItem
   Dim oSession As MAPI.Session
   Dim strID As String
   Dim strInternetHeaders As String
   Dim strTemp As String

   intFile = FreeFile
   Open strFilterFileDirectory & "Incoming.txt" For Output As #intFile

   strID = objMsg.EntryID
   Set olNS = Application.GetNamespace("MAPI")
   Set olMail = olNS.GetItemFromID(strID)

       On Error Resume Next
       Set oSession = CreateObject("MAPI.Session")
       oSession.MAPIOBJECT = olNS.MAPIOBJECT
'        oSession.Logon "", "", False, False

       Set objMessage = oSession.GetMessage(strID)

       'Get the headers from the message
       Set objFields = objMessage.Fields
       strInternetHeaders =
objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
       MsgBox strInternetHeaders

       oSession.Logoff
       On Error GoTo 0

   With olMail
       strSenderEmailAddress = .SenderEmailAddress
       strSenderName = .SenderName
       strSubject = .Subject
       strTo = .To
       strCc = .CC
       lngImportance = .Importance
       strBcc = .BCC
       strMailBody = .Body
       Print #intFile, "Incoming:"; vbCrLf _
           & "SenderEmailAddress:" & .SenderEmailAddress & vbCrLf _
           & "SenderName:" & .SenderName & vbCrLf _
           & "Subject:" & .Subject & vbCrLf _
           & "To:" & .To & vbCrLf _
           & "Cc:" & .CC & vbCrLf _
           & "Importance:" & .Importance & vbCrLf _
           & "Bcc:" & .BCC & vbCrLf _
           & "Body: " & vbCrLf _
           & .Body

       On Error Resume Next
       For Each objItem In .ItemProperties
           strTemp = ""
           With objItem
               strTemp = strTemp & "(1):" & .Name & vbCrLf
               strTemp = strTemp & "(2):" & .Type & vbCrLf
               strTemp = strTemp & "(3):" & .Value & vbCrLf
           End With
           Print #intFile, strTemp
       Next objItem
       On Error GoTo 0
   End With

   Set objFields = Nothing
   Set objMessage = Nothing
   Set oSession = Nothing
   Set olMail = Nothing
   Set olNS = Nothing

   Close #intFile
End Sub
Sue Mosher [MVP-Outlook] - 27 Oct 2005 23:50 GMT
No, you'd have to use Redemption. CDO is *always* subject to the security prompts, and Outlook objects don't expose the headers.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Thanx.
>
[quoted text clipped - 80 lines]
>    Close #intFile
> End Sub
Howard Kaikow - 28 Oct 2005 03:57 GMT
No, you'd have to use Redemption. CDO is *always* subject to the security
prompts, and Outlook objects don't expose the headers.

Is CDO subject to the security messages if I use a VB 6 COM add-in?
Howard Kaikow - 28 Oct 2005 04:07 GMT
> No, you'd have to use Redemption. CDO is *always* subject to the security
> prompts, and Outlook objects don't expose the headers.
>
> Is CDO subject to the security messages if I use a VB 6 COM add-in?

http://support.microsoft.com/default.aspx?scid=kb;en-us;327657&Product=ol2002
states that CDO Is not trusted via COM.

Like why does MessySoft impose such restrictions?
Having access to the full headers facilitates better filtering for SPAM.
Howard Kaikow - 28 Oct 2005 04:15 GMT
Can the SendMessage API be used to respond to the security warning dialog?
Sue Mosher [MVP-Outlook] - 28 Oct 2005 04:33 GMT
It might very well work. I know there is sample code for using SendKeys. (I'm not sure it still works in the latest versions.)

The best solution, of course, is to avoid having any prompts in the first place.
Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Can the SendMessage API be used to respond to the security warning dialog?
Howard Kaikow - 28 Oct 2005 05:42 GMT
It might very well work. I know there is sample code for using SendKeys.
(I'm not sure it still works in the latest versions.)

The best solution, of course, is to avoid having any prompts in the first
place.

I would not use SendKeys.
I'd use the approach in
http://www.standards.com/index.html?SetVBAProjectPassword
Howard Kaikow - 29 Oct 2005 11:48 GMT
>It might very well work. I know there is sample code for using SendKeys.
(I'm not sure it still works in the latest >versions.)

Where is that sample code?

I've tried using both SendKeys to no avail.
It seems that the security message is modal.

If it is indeed modal, then I cannot get the handle for it's window and
process with SendMessage.
Dmitry Streblechenko - 27 Oct 2005 23:54 GMT
Only if you are using Extended MAPI (C++/Delphi, no scripts) or Redemption
(any language) - http://www.outlookcode.com/d/sec.htm
Outlook Object Model or CDO 1.21 will produce a prompt.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

> Thanx.
>
[quoted text clipped - 81 lines]
>    Close #intFile
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.