Completing the Picture: POP3 and Mime
page 1 of 1
Published: 13 Dec 2004
Unedited - Community Contributed
Abstract
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.
by Web Team at ORCS Web
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 8029/ 19

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.com
www.aspnetmime.com

   Samples:
www.aspnetpop3.com/examples.aspx
www.aspnetmime.com/examples.aspx
www.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.


User Comments

Title: Server authentication   
Name: Scott Forsyth
Date: 2006-04-07 6:07:03 PM
Comment:
Hi Romulo,

That error has occured because your SMTP server doesn't allow relaying. That is a good thing is most cases. So, you will need to set your email username and password in your code so that you are appoved to send that message.

The other alternative is to send using the SMTP on the mail server. If you install IIS SMTP, make sure to enable 127.0.0.1 as an approved server. Then use 'localhost' as your SMTP server and it will work without entering any username/password.
Title: Server authentication   
Name: Romulo Rocha
Date: 2006-04-07 9:14:36 AM
Comment:
Hello, When I try to send email by SMPT, I receive this message:
This mail server requires authentication when attempting to send to a non-local e-mail address.
How can send a non-local email?
Thanks
Title: local SMTP   
Name: Brad Kingsley
Date: 2004-12-20 6:14:17 AM
Comment:
Do you have the MS SMTP service running on your machine? If not, that is the problem. If you aren't running SMTP, you can either install it or use a mail server on your local ISP's network (many ISPs are blocking external email servers now, so it's a good idea to use the one assigned to you by them).


~Brad Kingsley
Windows 2000 MCSE

http://www.orcsweb.com/
Powerful Web Hosting Solutions
#1 in Service and Support
Title: Can't use smtp server from my local machine   
Name: Mahmoud Tahoon
Date: 2004-12-19 12:16:23 PM
Comment:
Hello
I've tried to send emails from asp.net but always i faces the error about wrong smtp server name, i use my local machine and when i read your previous article (pop3 email) i found that you used the value "localhost" for the smtp server name i tried it but always the same error , could you please help me about that.
THANK YOU
Mahmoud Tahoon

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-07 8:14:57 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search