Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 ASPPop3 - Recieving Emails & Displaying
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 06 October 2003 :  21:39:07  Show Profile
Hi,

I am trying to configure ASPPop3 component thats installed on our Kiwihosting.net server to retrieve emails from our mail server and then take some data from the email and store it in the database. First off I just want to get the thing to open my emails. Here is the "How To" bit from their website at http://www.serverobjects.com/comp/Asppop3.htm :

[script]
The following code demonstrates how to use AspPOP3 from VBScript.

Set Mailer = Server.CreateObject("POP3svg.Mailer")
Mailer.RemoteHost = "mailhost.localisp.net"
Mailer.UserName = "myname"
Mailer.Password = "mypassword"
Mailer.MailDirectory = "d:\usermail\myname"
Mailer.OpenPop3

rem We could do multiple retrieves here but this demo only shows the
rem selected message.


Mailer.MailDirectory = "d:\usermail\myname"
Mailer.RetrieveToFile 1, "1.txt"
Mailer.ClosePop3

The file d:\usermail\myname\1.txt now holds the complete message text for this message. You could optionally do the following:

Set Mailer = Server.CreateObject("POP3svg.Mailer")
Mailer.RemoteHost = "mailhost.localisp.net"
Mailer.UserName = "myname"
Mailer.Password = "mypassword"
Mailer.OpenPop3

rem We could do multiple retrieves here but this demo only shows the
rem selected message.


Mailer.Retrieve 1
Mailer.ClosePop3

You can now use Mailer's properties to examine each part of the message
[/script]

So I came up with this, to get the email and display the body:

[script]
<%
Set Mailer = Server.CreateObject("POP3svg.Mailer")
Mailer.RemoteHost = "mail.domainname.co.nz"
Mailer.UserName = "username@domainname.co.nz"
Mailer.Password = "password"
Mailer.OpenPop3


Mailer.Retrieve 1
Response.Write "This message is " & _
Mailer.BodyText
Mailer.ClosePop3

%>
[/script]

(NOTE: I tried "username@domain.co.nz" and "username" both as the Mailer.UserName)

I stuck that in notepad, saved the asp file, uploaded it to my server, sent a test email, waited a bit then executed the file. But all it displayed was This message is. Has anyone had experience with this and can help me out a bit here please.

What I eventually want to do is have this script check for emails, and if they have a certain subject line, extract various bits of data to my database, if not, ignore it.

Doug G
Support Moderator

USA
6493 Posts

Posted - 07 October 2003 :  02:30:29  Show Profile
Mailer.open should have a return value available to let you know if you connected to the pop server successfully. I'm not familiar with this component but somewhere there must be a way to know that you've connected and logged on OK.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  19:00:53  Show Profile
I had a look at their site and there doesn't seem to be any...

Cheers,
WeeVaa.

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 07 October 2003 :  19:39:22  Show Profile
I have used JMail POP3 and AdminSystem.Net POP3, both of those controls provide a connection status when you log on the pop server. I don't know about the control you're using, but my guess is you are not getting connected which is why you get no message text.


======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  20:17:28  Show Profile
OK, we have W3 Jmail component installed on our server (we are using kiwihosting.net). Do you have any sample code for Jmail that would simply display the email on screen (or even better, extract stuff from the body and put it in the database ).

Cheers,
WeeVaa.

Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  21:17:20  Show Profile
I have found this script for JMail, but it just displays a blank screen. I have tried all combinations of username, username@domain.com, localhost, mail.domain.com and all that. But still just a blank screen.


<%
Function GetPopMail(ByVal usr, ByVal pass, ByVal mailserver, _
    ByVal mailport, byVal bShowHeaders)
	'declare variables
	Dim pop, headers, i, messages, ct, message

	'create jmail pop3 object
	Set pop = CreateObject("JMail.POP3")
	
	'connect to account
	pop.Connect username, password, localhost, 110

	'download mail headers
	pop.DownloadHeaders

	'download mail messages
	pop.DownloadMessages

	'get handle to the messages object
	Set messages = pop.Messages

	'count of messages retrieved
	ct = messages.count - 1

	'if there's messages...
	if ct >= 1 then

		'loop through messages
		for i = 1 to ct

			'get handle to message object
			Set message = messages.item(i)

			'show headers or whole email...
			if bShowHeaders then

				'print header
				Response.Write( message.Text & "<BR><BR>")
			else

				'print subject and body
				Response.Write( "<B>" & _
                                    message.subject & "</B><BR>" )
				Response.Write( message.body & _
                                    "<BR><BR>" )
			end if

			'free message handle
			Set message = nothing
		next
	else

		'no messages
		Response.Write( "no messages on " & mailserver )
	end if

	'disconnect from server
	pop.disconnect

	'release messages handle
	Set messages = Nothing

	'free jmail pop3 object
	Set pop = Nothing
End Function
%>

Cheers,
WeeVaa.

Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 07 October 2003 :  22:00:02  Show Profile
I don't have JMail code handy right now, and I guess I need some kind of login now to get to their documentation on the website. I remember checking for a message count after connecting, something like count=pop.count

Try putting a couple selective response.writes in your code for debugging, such as response.write "Count is: " & ct



======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  22:51:00  Show Profile
I edited the script like so, to include a few response writes to show me where it got up to:


<%
response.write "begin"
%>
<%
Function GetPopMail(ByVal usr, ByVal pass, ByVal mailserver, _
    ByVal mailport, byVal bShowHeaders)
	'declare variables
	Dim pop, headers, i, messages, ct, message
response.write "connecting"
	'create jmail pop3 object
	Set pop = CreateObject("JMail.POP3")
	
	'connect to account
	pop.Connect username, password, mail.server.co.nz, 110
response.write "connected"
	'download mail headers
	pop.DownloadHeaders

	'download mail messages
	pop.DownloadMessages

	'get handle to the messages object
	Set messages = pop.Messages

	'count of messages retrieved
	ct = messages.count - 1
	response.write "Count is: " & ct

	'if there's messages...
	if ct >= 1 then

		'loop through messages
		for i = 1 to ct

			'get handle to message object
			Set message = messages.item(i)

			'show headers or whole email...
			if bShowHeaders then

				'print header
				Response.Write( message.Text & "<BR><BR>")
			else

				'print subject and body
				Response.Write( "<B>" & _
                                    message.subject & "</B><BR>" )
				Response.Write( message.body & _
                                    "<BR><BR>" )
			end if

			'free message handle
			Set message = nothing
		next
	else

		'no messages
		Response.Write( "no messages on " & mailserver )
	end if

	'disconnect from server
	pop.disconnect
	response.write "disconnected"

	'release messages handle
	Set messages = Nothing

	'free jmail pop3 object
	Set pop = Nothing
End Function
%>


But all it displays is "begin", and none of the others that are actually in the script. That would indicate the script isn't working. Have you tested the above code on your server?

Cheers,
WeeVaa.

Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 07 October 2003 :  22:53:29  Show Profile
you aren't actually calling the function

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  23:03:42  Show Profile
Oh. So how do I do that

Edited by - eggyfarts on 07 October 2003 23:05:29
Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 07 October 2003 :  23:49:25  Show Profile
I changed the code to this, and it works except I'm getting this error:

Microsoft VBScript compilation error '800a0408'

Invalid character

/pop3.asp, line 4

MyUsername= username@server.co.nz


I need the @ symbol because if I just put "username", I can't login, it has to be "username@domain.co.nz". Is there a way to get around this?

Here is the re-worked code.

<%
response.write "begin"

MyUsername= username@server.co.nz
MyPassword = password
Mailserver = mail.server.co.nz
%>
<%
Function GetPopMail

	'declare variables
	Dim pop, headers, i, messages, ct, message
response.write "connecting"
	'create jmail pop3 object
	Set pop = CreateObject("JMail.POP3")
	
	'connect to account
	pop.Connect MyUsername, MyPassword, Mailserver

response.write "connected"

	'download mail headers
	pop.DownloadHeaders

	'download mail messages
	pop.DownloadMessages

	'get handle to the messages object
	Set messages = pop.Messages

	'count of messages retrieved
	ct = messages.count - 1
	response.write "Count is: " & ct

	'if there's messages...
	if ct >= 1 then

		'loop through messages
		for i = 1 to ct

			'get handle to message object
			Set message = messages.item(i)

			'show headers or whole email...
			if bShowHeaders then

				'print header
				Response.Write( message.Text & "<BR><BR>")
			else

				'print subject and body
				Response.Write( "<B>" & _
                                    message.subject & "</B><BR>" )
				Response.Write( message.body & _
                                    "<BR><BR>" )
			end if

			'free message handle
			Set message = nothing
		next
	else

		'no messages
		Response.Write( "no messages on " & mailserver )
	end if

	'disconnect from server
	pop.disconnect
	response.write "disconnected"

	'release messages handle
	Set messages = Nothing

	'free jmail pop3 object
	Set pop = Nothing
End Function
%>
<%= GetPopMail %>

Cheers,
WeeVaa.

Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 08 October 2003 :  00:54:02  Show Profile
OK, its sorted now, they had to be inclosed in quotes.

Cheers,
WeeVaa.

Go to Top of Page

eggyfarts
Junior Member

New Zealand
200 Posts

Posted - 08 October 2003 :  01:57:27  Show Profile
OK, here is my new and improved code, its all working, it connects to the server and displays the email:


<% @LANGUAGE=VBSCRIPT %>
<% 


Set pop3 = Server.CreateObject( "JMail.POP3" )

pop3.Connect "username@server.com", "password", "mail.server.com"

Response.Write( "You have " & pop3.count & " emails in your mailbox!<br><br>" )

if pop3.count > 0 then
Set msg = pop3.Messages.item(1) 

%>
<html>
<body>
<TABLE>
 <tr>
  <td>Subject</td>
  <td><%= msg.Subject %></td>
 </tr>
 <tr>
  <td>From</td>
  <td><%= msg.FromName %></td>
 </tr>
 <tr>
  <td>Body</td>
  <td><pre><%= msg.Body %></pre></td>
 </tr>
</TABLE>
</body>
</html>
<%

end if

pop3.Disconnect

%>


Now that all thats sorted, what I want to do is this. Have this script check the server for emails, if there are no emails on the server, simply disconnect. If there are emails, then download the headers for them. Then check the first email, if the subject matches the preset subject variable then keep going and download the message body as well, if not, go on to the next message.

When it finds a message with a particular subject line, I want it to look at the body, and extract a few things to the database and then delete the email, and keep going with the search, then when all messages are read, disconnect.

All the emails I want to look at will be in the same format, with the same subject line. The body format will be:

Your auction for "Title of Auction"
(auction no. 1234567) has finished. The auction passed your reserve price
and has successfully sold.

The details of the winning bid are:
AMOUNT: $265.00
TOP BIDDER: SomePerson
EMAIL: mailto:Someperson@server.com


What I want to do is extract the amount of the bid and the bidders email address, as well as the 7 number "auction no." to my database, to be used later on. I am stuck as to go about the first part (well actually the whole thing), which is getting the script to check for emails and stop when it finds one that matches the subject line.

I have found a google cached site that explains what each thing in JMail.POP3 does, URL copy + paste from below (its a large url!), but my skills aren't too great. Can anyone out there help me with this?
TIA for any help at all.

URL: http://216.239.57.104/search?q=cache:JPd1dkAuHGEJ:www.duplo.se/files/pdf/w3_JMail4_REF.pdf+jmail.pop3+asp+DeleteSingleMessage&hl=en&ie=UTF-8#2
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.37 seconds. Powered By: Snitz Forums 2000 Version 3.4.07