ASP Code
  Home arrow ASP Code arrow Page 4 - Inbox and Outbox Manipulation in ASP
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Inbox and Outbox Manipulation in ASP
By: Burhan Khan
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 194
    2005-02-22

    Table of Contents:
  • Inbox and Outbox Manipulation in ASP
  • CDO is not everything
  • Receiving Email: Inbox
  • Inbox using CDO

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Inbox and Outbox Manipulation in ASP - Inbox using CDO


    (Page 4 of 4 )

    You can also see these email messages by using ASP. A Session object is considered a top-level object, meaning it can be created directly from a MS VB program. The Session object contains session-wide settings and options. Microsoft's CDO (Collaborative Data Object) allows you to process this incoming email as a series of objects. First you need to create an instance of CDONTS.Session. It can be created like this:

       objSession = Server.CreateObject("CDONTS.Session")

    An application using the CDO for NTS Library binds by address to the mailbox you specify in the LogonSMTP parameters:

       objSession.LogonSMTP "User Name", "user@example.com"

    When CDO for NTS is running with IIS, the Inbox is a common folder shared by all recipients and applications, and containing all undeleted messages received by IIS. After these two steps, you can use properties ( ".inbox," ".outbox," ".version," etc…) of CDONTS.Session object to get your desired results.

    ' open the inbox folder

    Set objInbox = objSession.Inbox

    ' retrieve the messages collection

    Set strMessages = objInbox.Messages

    ' Go to specific message

    Set strMessage = strMessages(intMsgID)

    ' retrieve message information

    strMessage.Subject                       ' subject of message

    strMessage.Sender                        ' sender

    strMessage.Text                           ' actual message

    After all, you need to log off your CDONTS session by using the ".LogOff" method.

    objSession.LogOff

    That is all the work you need to do to receive email from ASP code.

    To review, the whole code needed to check the inbox in ASP is:

    <%

    'create our variables

    Dim objSession , strMessage , strMessages , objInbox , intMsgID

    'create an instance of the CDONTS.Session object

    Set objSession = Server.CreateObject("CDONTS.Session")

    'this is your logon details

    objSession.LogonSMTP "password" , "email@youraddress.com"

    'open the inbox folder

    Set objInbox = objSession.Inbox

    'retrieve the messages collection

    Set strMessages = objInbox.Messages

    intMsgID = Trim(Request.QueryString("MsgId"))

    If ("" = intMsgID Or Not IsNumeric (intMsgID)) Then

    'display all the messages

    For Each strMessage in strMessages

    i = i + 1

    Response.Write "<a href="""

    Response.Write Request.ServerVariables("SCRIPT_NAME")

    Response.Write "?MsgId=" & i & """>" & strMessage.Subject

    Response.Write "</a>"

    Response.Write " sent by : " & strMessage.Author

    Response.Write "<br>"

    Next

    Else

    Set strMessage = strMessages(intMsgID)

    Response.Write "Subject : " & strMessage.Subject & "<br>"

    Response.Write "Sender : " & strMessage.Sender & "<br>"

    Response.Write "Message : " & strMessage.Text

    End If

    'log off from the session

    objSession.LogOff

    %>

    In this code MsgId is a query string value which shows that you want to see any specific email message. If MsgId is not given in the URL, then all of the emails’ subjects will be shown, so you can select any email.

    Conclusion

    Sending and receiving email from Web pages is obviously useful because you often cannot use Outlook Express or other mail programs such as Eudora and Amoel to receive emails. This may be because you are far from your computer, in another city or country, or enjoying your trip or away with family and friends for the holidays. Using a Web page for sending and receiving email can help you access your email throughout the world.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Why are you talking about the NT4 update?Sheezeesss... who's still running that...
       · 2000 and XP are also NT bassed OS.By NT4 means, 2000 or XP (Service pack 4...
       · Saying "NT4" is *NOT* the same as saying "Windows 2000 with service pack...
       · hi this is thoma, just a month before i started my career in ASP. here i...
       · So why don't you contribute instead of berating someone else who has taken the time...
     

    ASP CODE ARTICLES

    - ASP Forms
    - ASP: The Beginning
    - Getting Remote Files With ASP Continued
    - Inbox and Outbox Manipulation in ASP
    - Relational DropDownList Using VB.NET
    - Ad Tracking URL Hits
    - Use ViewState to display one record per page...
    - Send Email using ASP.NET formatted in HTML
    - ASP File Explorer
    - ASP/XML Interview questions by Srivatsan Sri...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek