One of the first things many web programmers tackle within their first couple of applications is sending email from code. Yet fewer web developers have ventured into managing a POP3 email account from a web application. That's not to say there aren't many applications that require incoming email. Examples include:
- allowing a user to send a file by email that can be automatically placed on a website somewhere.
- responding to commands sent by email
- handling email for a team environment
- creating a web based email application
- . . . and the list goes on.
Enter
Advanced Intellect with an easy-to-use, yet powerful solution. In a
past article, I covered their SMTP component, but this time we'll look at aspNetPOP3 and aspNetMime which together completes the set.
Advanced Intellect gives a nice overview of SMTP, POP3 and MIME on their website and how their products fit in.
What is the difference between MIME, POP3 and SMTP?
"MIME, POP3 and SMTP are all email related protocols. POP3 and SMTP are actually transport protocols. POP3
(aspNetPOP3) is used for retrieving email, while SMTP
(aspNetEmail) is used for sending email. MIME
(aspNetMime) is used to read and parse the email message itself, not for transporting the message."
Source Since the examples on their website cover everything needed to get going, I'll include just one example below that allows you to specify your POP3 server, username and password and get a message count and total inbox size for that account. Further examples can be found at
www.aspnetpop3.com and
www.aspnetmime.com with a good demo and source code for aspNetMime
www.aspnetmime.com/demo.aspx.
Like usual, I've kept this as simple as possible without attempting to 'pretty-it-up' so as not to clutter the example much.
<%@ Page Language="VB"%>
<script runat="server">
Private Sub btnCheck_Click(Sender As Object, e As EventArgs)
Dim pop As aspNetPOP3.POP3
Try
pop = New aspNetPOP3.POP3(txtServer.Text, txtUsername.Text, txtPassword.Text)
'connect to the POP3 server
pop.Connect()
'Log in memory which doesn't require write access to the file system
pop.LogInMemory = True
'get the number of messages and the size of the inbox
pop.PopulateInboxStats()
lblStatus.Text = "There are " & pop.InboxMessageCount & " messages waiting. " _
& "The total inbox size is " & pop.InboxSize & " bytes."<br>
'Close the POP3 Connection
pop.Disconnect()
Catch
lblStatus.Text = "<font color='red'>There was an error, the error was: " _
& err.Description & "</font>"
End Try
End Sub
</script>
<html>
<head>
<title>ASPNetPOP3 Sample</title>
</head>
<body>
<b>ASPNetPOP3 Sample</b>
<form runat="server">
<asp:Label id="lblStatus" runat="server"></asp:Label>
Server: <asp:TextBox id="txtServer" runat="server"></asp:Textbox>
Username: <asp:TextBox id="txtUsername" runat="server"></asp:Textbox>
Password: <asp:TextBox id="txtPassword" runat="server"></asp:TextBox>
<asp:Button id="btnCheck" text="Check Email Count" runat="server"
onclick="btnCheck_Click"></asp:Button>
</form>
</body>
</html>
So now you can see how easy it is to develop POP3 applications from ASP.Net and the power afforded to you by these two components. Advanced Intellect makes programming incoming and outgoing email surprisingly easy without missing any of the control desired by even
the most demanding power users.
Links:
Main Website:
www.aspnetpop3.comwww.aspnetmime.com Samples:
www.aspnetpop3.com/examples.aspxwww.aspnetmime.com/examples.aspxwww.aspnetmime.com/demo.aspx By Scott Forsyth, Director of Technology at ORCS Web, Inc. - a company that provides managed hosting services for clients who develop and deploy their applications on Microsoft Windows platforms.