.NET Components for Mobility

receiving a new email message

Last post 09-26-2008 8:39 AM by sergiocristiano. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 08-01-2008 4:35 AM

    receiving a new email message

    hi,

    i'm using ITH 3.3 and i try out the event-handle if a new email arrives in the inbox. this is code i use:

     Public Sub Form1_MessagingItemCreated(ByVal sender As Object, ByVal e As MessagingItemEventArgs)
            Dim ex As New EmailMessage(e.ItemId)
            Dim subject As String
            Dim body As String
            Dim i As Integer
            Dim notfall As Boolean
            Dim id As String
            Dim msg As EmailMessage
            Application.DoEvents()
            System.Threading.Thread.Sleep(1000)
            Application.DoEvents()
            subject = ex.Subject
            For i = 0 To os.EmailAccounts(0).Inbox.Count - 1
                msg = os.EmailAccounts(0).Inbox.Item(i)
                If msg.Read = False Then
                    msg.Read = True
                    msg.Update()
                    subject = msg.Subject
                    body = msg.BodyText
                    writeLog("Form1_MessagingItemCreated", "Neue email eingegangen: " + subject + "|" + body, False)

                    writeLog("Form1_MessagingItemCreated", "Neue email eingegangen (ex): " + ex.Subject.ToString + "|" + ex.BodyText.ToString, False)

                End If
            Next
        End Sub

    important are the line writeLog. why? easy to explain: the results are different:

     Neue email eingegangen: mySubject|myBodytext

    and 

     Neue email eingegangen (ex): mySubject|

    or sometimes: 

     Neue email eingegangen (ex): |

    or in some cases:

     Neue email eingegangen (ex): mySubject|myBodytext

     

    so why are there 3 kinds of the result?

    my workaround to get the incomming message take to long to get the messagedata :(

    so are there any tips to get the whole message information without my workaround? why does the event not work correctly?

    thanks.

    hibbert.de 

    sorry for my bad english
  • 08-04-2008 7:29 AM In reply to

    Re: receiving a new email message

    The Created event fires when a new message item is created in a folder, however at this stage not all the properties are populated. In order to support this you need to store the ItemId of the new item and then wait for the Modified event for this item. In the eventargs for a modification you can check the property ids returned to see if they contain the message body. Usually there are 1 or 2 modification events after the item is created. Another simpler approach would be to introduce a time delay after the item is created to give the message transport time to save the properties. The exact sequence of properties written varies between versions of Windows Mobile and depending on the message transport- ActiveSync, POP, IMAP etc

    Peter

    Peter Foot
    Microsoft Device Application Development MVP
    www.peterfoot.net | www.inthehand.com
  • 08-05-2008 1:39 PM In reply to

    Re: receiving a new email message

    Hello guys

    Peter, i had the same problem. Somes fields from message are empty.

    So, you gave two options

    In the first option, How can i implements a verification to know when the message and his fields are ready?

    I only tried to implement a "Thread.Sleep" in the second option with a time well large, but also return empty fields.

     

    Thanks

  • 08-07-2008 8:29 AM In reply to

    Re: receiving a new email message

    Hello there,

    i've tried this one here, but it's always the same: i cant get the hole new message:

    Public Class frmMain
        Public newMailList As New ArrayList

    '...

       Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            AddHandler os.MessagingItemCreated, AddressOf Form1_MessagingItemCreated
            AddHandler os.MessagingItemModified, AddressOf Foorm1_MessagingItemModified

    end sub

    Private Sub Foorm1_MessagingItemModified(ByVal sender As Object, ByVal e As MessagingItemEventArgs)
            Dim ex As New EmailMessage(e.ItemId)
            Dim idx As Integer
            idx = newMailList.IndexOf(e.ItemId.ToString)
            If idx > -1 Then
                newMailList.RemoveAt(idx) 'mail wieder leeren
                MsgBox("Subject: " + ex.Subject + vbCrLf + ex.BodyText)
            End If
        End Sub

        Public Sub Form1_MessagingItemCreated(ByVal sender As Object, ByVal e As MessagingItemEventArgs)
            Dim ex As New EmailMessage(e.ItemId)
            newMailList.Add(e.ItemId.ToString)

    end sub 

     if a new email arrives it take minutes if the messagebox popps up. sometime i do not get a messagebox, or i get it when the next mail arrives...

     

    so whats wrong with code or with the libary?

     

    thanks hibbert.de 

    sorry for my bad english
  • 08-08-2008 3:42 AM In reply to

    Re: receiving a new email message

    I have a sample project which shows how to handle the combination of Created/Modified events to catch when a message is available and it's properties are filled in. I will post it here shortly.

    Peter

    Peter Foot
    Microsoft Device Application Development MVP
    www.peterfoot.net | www.inthehand.com
  • 09-26-2008 8:39 AM In reply to

    Re: receiving a new email message

     Hello peter

     

    Did you post the sample project that you commented?

     

    i look forward,

     

    thank's

Page 1 of 1 (6 items)
Copyright © 2001-2008 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy.