| Author |  | 
      
        | Tom B. Guest Group
 
  
 
 Joined: 10 November 2003
 Online Status: Online
 Posts: 262
 | 
          Hello,
           | Posted: 28 January 2005 at 8:04pm | IP Logged |   |  
           | 
 |  
 I'm trying to loop through all emails and get the details of each email (From, Subject, Date and full body)
 using ASP.NET (VB). Do you have an example how to do that ? Thanks in advance.
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          There is POP3 sample project for ASP.NET in MailBee Programming Samples menu of MailBee group in Programs menu. Also, there is a number of ASP samples there (the code for them is nearly the same as for ASP.NET). These samples cover different aspects of mail receiving.
           | Posted: 29 January 2005 at 4:37am | IP Logged |   |  
           | 
 |  
 Also, in your particular case, you can start with the code like below:
 
 
 
| Code: 
 
    
    | 
      
       | Dim oMailer As Object, oMsgs As Object, oMsg As Object
 
 oMailer = Server.CreateObject("MailBee.POP3")
 
 ' Log file allows you to debug more easily
 oMailer.LogFilePath = "C:\pop3_log.txt"
 oMailer.EnableLogging = True
 
 oMailer.LicenseKey = "License Key"
 oMailer.ServerName = "mail.server.com"
 oMailer.UserName = "user"
 oMailer.Password = "pass"
 
 oMsgs = oMailer.RetrieveMessages()
 
 If IsNothing(oMsgs) Then
 Response.Write "Error, see log"
 Else
 For Each oMsg In oMsgs
 Response.Write "From: " & oMsg.PureFromAddr & "<br>"
 Response.Write "To: " & oMsg.PureToAddr & "<br>"
 Response.Write "Subject: " & oMsg.Subject & "<br>"
 Response.Write "Date: " & oMsg.Date & "<br>"
 Response.Write "Body:<br>" & oMsg.BodyText & "<br>====<br>"
 Next
 End If
 
 oMailer.Disconnect()
 
 |  |  |  
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Tom B. Guest Group
 
  
 
 Joined: 10 November 2003
 Online Status: Online
 Posts: 262
 | 
          Thanks a lot Alex, that was what I was looking for.
           | Posted: 29 January 2005 at 10:11am | IP Logged |   |  
           | 
 |  | 
       
        | Back to Top |     | 
       
       
        |  | 
        | small fix Guest Group
 
  
 
 Joined: 10 November 2003
 Online Status: Online
 Posts: 262
 | 
          Well I had problem with the code above if someone uses ASP IIS 6.0 here is the correction
           | Posted: 03 June 2006 at 12:17am | IP Logged |   |  
           | 
 |  ==========
 
 <%
 Dim oMailer, oMsg, oAttach
 Dim I, nMessageNumber
 
 set oMailer = Server.CreateObject("MailBee.POP3")
 
 ' Log file allows you to debug more easily
 oMailer.LogFilePath = "C:\pop3_log.txt"
 oMailer.EnableLogging = True
 
 oMailer.LicenseKey = "MBC****"
 oMailer.ServerName = "mail.server.com"
 oMailer.UserName = "user"
 oMailer.Password = "pass"
 
 set oMsgs = oMailer.RetrieveMessages()
 
 If Isnull(oMsgs) Then
 Response.Write "Error, see log"
 Else
 For Each oMsg In oMsgs
 Response.Write "From: " & oMsg.PureFromAddr & "<br>"
 Response.Write "To: " & oMsg.PureToAddr & "<br>"
 Response.Write "Subject: " & oMsg.Subject & "<br>"
 Response.Write "Date: " & oMsg.Date & "<br>"
 Response.Write "Body:<br>" & oMsg.BodyText & "<br>====<br>"
 Next
 End If
 oMailer.Disconnect()
 %>
 ======
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          Thank you for the note. IsNothing function is actually missing in ASP (it was introduced in VB.NET/ASP.NET).
           | Posted: 03 June 2006 at 8:00am | IP Logged |   |  
           | 
 |  
 However, it's not correct to replace it with IsNull since Nothing and Null are different values and POP3.RetrieveMessages method never returns Null. To check for Nothing in classic ASP, it's better to use:
 
 Another difference between classic and .NET ASP version is "Set" statement (such as in "Set oMailer = Server.CreateObject..." declaration). It's required in classic ASP/VB, while it's no longer used in .NET.
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  |