Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Application_NewMail fetching older mails from Inbox

Application_NewMail fetching older mails from Inbox

Scheduled Pinned Locked Moved Visual Basic
databasecollaborationhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    manju 3
    wrote on last edited by
    #1

    Hi Team, I am trying to trigger a macro whenever a new mail is recieved in the outlook. Here is my code :

    Private Sub Application_NewMail()

    'To set the email folder to INBOX, set to MAPI
    Dim onamespace As Outlook.NameSpace
    Set onamespace = Outlook.GetNamespace("MAPI")

    Dim myfolder As Outlook.Folder
    Set myfolder = onamespace.GetDefaultFolder(olFolderInbox)

    Dim email As Outlook.MailItem
    Set email = Outlook.CreateItem(olMailItem)
    Dim attachment As Outlook.attachment

    For Each email In myfolder.Items
    MsgBox email.SenderName
    Next email
    End Sub

    But i am not getting the new mail which i sent at present. myFolder.Items is pointing to inbox but fetching older mails I am getting the "older" mails. Can anyone help me on where i am going wrong here Thanks Manju

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups