none
POP3 Email Attachment

    Question

  • I need to check if an email is attached and is more his type is XML. Somebody help me?


    Cristiano Rodrigues
    Thursday, August 06, 2009 2:18 PM

Answers

  • Here is a snippet that checks for Html based on the <head> element. You could modify this for Xml.

    public static bool CheckIfHtmlBody(XLANGMessage msg)
    {
    // An Html body is a separate mime part but won't
    // have a MIME.FileName, so we have to avoid this possibility.
    bool IsHtmlBody = false;
    try
    {
    if (msg.Count > currentCount)
    {
    // Read the message
    StreamReader re = new StreamReader((Stream)msg[currentCount].RetrieveAs(typeof(Stream)));
    //re.Read();
    string strMsg = re.ReadToEnd();
    re.Close();
    if (strMsg.Contains("<head>"))
    {
    IsHtmlBody = true;
    }
    }
    }
    catch (Exception e)
    {
    throw;
    }
    
    finally  { 
    msg.Dispose();
    
    }
    return IsHtmlBody;
    }

     Thanks,

     

     


    If this answers your question, please use the "Answer" button to say so | Ben Cline
    Friday, August 07, 2009 7:26 PM
    Moderator

All replies

  • You have to typically check the message part to see what data exists. This can be done by passing the XLangMessage to a .NET component and streaming out the content from there to check for the data.

    For Xml you would check that it isn't binary and has an Xml declaration, etc.

    Thanks,
    If this answers your question, please use the "Answer" button to say so | Ben Cline
    Friday, August 07, 2009 12:09 AM
    Moderator
  • Thanks for reply. You have a sample?


    Cristiano Rodrigues
    Friday, August 07, 2009 12:32 AM
  • Here is a snippet that checks for Html based on the <head> element. You could modify this for Xml.

    public static bool CheckIfHtmlBody(XLANGMessage msg)
    {
    // An Html body is a separate mime part but won't
    // have a MIME.FileName, so we have to avoid this possibility.
    bool IsHtmlBody = false;
    try
    {
    if (msg.Count > currentCount)
    {
    // Read the message
    StreamReader re = new StreamReader((Stream)msg[currentCount].RetrieveAs(typeof(Stream)));
    //re.Read();
    string strMsg = re.ReadToEnd();
    re.Close();
    if (strMsg.Contains("<head>"))
    {
    IsHtmlBody = true;
    }
    }
    }
    catch (Exception e)
    {
    throw;
    }
    
    finally  { 
    msg.Dispose();
    
    }
    return IsHtmlBody;
    }

     Thanks,

     

     


    If this answers your question, please use the "Answer" button to say so | Ben Cline
    Friday, August 07, 2009 7:26 PM
    Moderator