Mail plugin with pop3 support

Thanks! :lol:

I will test that in a minute. How about that java.lang.classCastException that I get when passing header.getSentDate()?

I forgot to ask, could you sent me the .log.txt when this happens?

Now I always get “null” when I do

var headers = plugins.mail.recieveMail(userName, userPass, true , 1 , null, hostname);

??

and the log says

java.lang.NullPointerExceptionjava.lang.NullPointerException
at com.servoy.r2.plugins.mail.MailServerUtils.createAddressString(MailServerUtils.java:133)
at com.servoy.r2.plugins.mail.MailServerUtils.createMailMessage(MailServerUtils.java:38)
at com.servoy.r2.plugins.mail.MailServer.recieveMail(MailServer.java:213)
at com.servoy.r2.plugins.mail.MailProvider.js_recieveMail(MailProvider.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:289)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1237)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1940)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
at com.servoy.j2db.scripting.e.call(Unknown Source)
at com.servoy.j2db.develop.debugger.n.a(Unknown Source)
at com.servoy.j2db.develop.debugger.n.access$14(Unknown Source)
at com.servoy.j2db.develop.debugger.n$3.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Hi Jan

Downloaded latest version of Mail Plugin - your post 17 Sep 1.32pm - but cannot get started.

Trying to test by downloading first few messages but after a short delay [msgs] always returns null.


//Recieve mails from pop3 account
var msgs = plugins.mail.recieveMail(‘ztvo0afzzzzz’, ‘WnKN2rB7Xzzzzz’, true);
if (msgs != null) //if is null error occurred!
{
// for (var i = 0 ; i < msgs.length ; i++)
for (var i = 0 ; i <=6 ; i++)
{
var msg = msgs

------------------------------------------
Have tried with two different mail accounts/providers.

Servoy Developer
Version R2 2.1-build 310
Java version 1.4.2-38 (Mac OS X)

I am getting inconsistent results, too.

I am using office accounts where I know that mails are waiting for collection to test.

I can get mail from one account but not the other five that I have tried.

I have ‘null’ returned for ‘msgs’ in those instances.

I have used the sample code which does work fine on the account which responds and which shows the output correctly as I step through the method !

Cheers
Harry

Sorry should have included:

Servoy Developer
Version R2 2.1-build 310
Java version 1.4.1_03-b02 (Windows XP)

Like Harry I am checking accounts where I know there are plenty of messages although they will have been read by Outlook - does this set a flag that’s triggering the ‘null’ return??

GrahamG

I know that the messages that I can see have NOT been read.

I have sent the messages to the target accounts myself and attempted to read them with the mail PlugIn before the mail clients have accessed them !

Also the mail clients of target test accounts are set to delete the messages from the server once downloaded - so the messages up there should be virgin messages anyway !

‘Curiouser and curiouser’, said Alice !

Harry

patrick:
Now I always get “null” when I do

It seems the cc header is not present at all when empty on some mailserver, fixed: http://downloads.servoy.com/beta/2.1_product/mail.jar

I have a few questions about the pop3 plugin:

1.) I have a method that only downloads the headers. That is working fine.
Now i have the following method, that must only download the current mail:

var recieveMode = 1;//0=FULL,1=HEADERS_ONLY,2=NO_ATTACHMENTS
var msgs = plugins.mail.recieveMail(p_username, p_password, true,recieveMode, senddate);

senddate is a column with the Senddate in it.

But I’ll get the following error:

java.lang.ArrayIndexOutOfBoundsException

What am I doing wrong?

2.) When I do this: (sample code)

var attachments = msg.getAttachments()
if (attachments != null) 
{
	for (var j = 0 ; j < attachments.length ; j++)
	{
		var attachment = attachments[j]
		//application.output(attachment.getName())
		var attachmentDataByteArray = attachment.getData()
		//write attachmentDataByteArray to a file...
	}
}

Does that mean, that when I do this in a client, that an attachment of about 4MB, is first downloaded to (the client) variable: attachments and if I put it in the database, is the whole 4mb uploaded again??

  1. In (for example) Outlook there is a function, that you can keep messages on the server for let’s say: 20 days.
    Is this standard email-functionality, or is it something that only Outlook does?

  2. Jan, you said that there was no unique emailnumber. In almost all the pop3 beans you find something like this:
    elements.bean_680.getMessageUID(number) or
    elements.bean_680.getNoOfMessage()
    Now we have to download always all the headers, to determe how many emails there are, en determe which emails must be downloaded.
    If there are 20 message, this is not a problem, but if there are 100, this is a problem.
    A customer of us is using pop3/imap server. The imap-server is reachable by a webbrowser too. So if we do a pop3 session, we must leave the message on the server, because else the message would not be seen in the (imap) webbrowser.

Is there an easier (less overhead) way to do this?

5.) In the debugger I see also function, like: notify and notifyAll
What does that do?

6.) Why is the getReceivedDate() always empty?? (returning null)

  1. fixed http://downloads.servoy.com/beta/2.1_product/mail.jar
  2. well yes, you first recieve it and then put it in the database
  3. outlook, we could provide a method to delete a specific msg to get same behaviour,like deleteServerMail(sentdate)
  4. numberofmsg is no problem, but recieveing headers is about 100bytes per header, seems not like a problem to me.
  5. javamethods do not call them, they are hidden in normal use.
  6. recieve date is filled in by the mail client, which in our case your method, so it is null.
  1. Thanks, I give it a try
  2. This could be problematic for small-broadband-clients
    because you have to download first 4mb than upload 4 mb again, and than download 4mb again, to view it. that is: 12MB data, only to put it in a column.
    It would be handy, that you could put attachments in the database directly, without loading the first to the client.
  3. would be nice.
  4. ok, I thought that they would be bigger
  5. This one I don’t really get. I am downloading emails, from an emailserver that is also reachable from a webclient. In the webclient I see a sendate and a receiveddate. When I download it with the pop3 plugin, the receiveddate is null. I would expect else.
  1. to view not needed to download again, it is one download and one db insert. (how whould you do this otherwise?) better not download attachements on small-broadband-clients then.
  2. we use a SUN java mail lib, which seems not to provide a recieve date, but why do you not mark the mail with a “new Date” as being the recieve date when you recieve the mail?

6.) Oke, but why is there a function: msg.getReceivedDate() ? :lol:
You don’t have to answer! :lol:

It is availible on the java objects so we forwarded them to javascript, maybe in the future the recieve date is filled in

An performance enhancement is made for headers only http://downloads.servoy.com/beta/2.1_product/mail.jar
Thanks to HJK for pointing this out.

I am still getting “null” and in the log I see this error when retrieving mail:

java.lang.NullPointerExceptionjava.lang.NullPointerException
at com.servoy.r2.plugins.mail.MailServerUtils.createAddressString(MailServerUtils.java:133)
at com.servoy.r2.plugins.mail.MailServerUtils.createMailMessage(MailServerUtils.java:38)
at com.servoy.r2.plugins.mail.MailServer.recieveMail(MailServer.java:213)
at com.servoy.r2.plugins.mail.MailProvider.js_recieveMail(MailProvider.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:289)
at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1237)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1940)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94)
at com.servoy.j2db.scripting.e.call(Unknown Source)
at com.servoy.j2db.develop.debugger.n.a(Unknown Source)
at com.servoy.j2db.develop.debugger.n.access$14(Unknown Source)
at com.servoy.j2db.develop.debugger.n$3.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

fixed http://downloads.servoy.com/beta/2.1_product/mail.jar

the download doesn’t work anymore.
Does anyone know a miror for downloading this plugin ?

Sorry we forgot to post here, it is now included in Servoy 2.1.1.
See http://forum.servoy.com/viewtopic.php?t=3014