Make JavaMail fast - multithreading

I am trying to add email notification features to my Restlet server. I just learned today from Stackoverflow that Java Mail is synchronous.
So there are two obvious options: 1. use a really fast SMTP server 2. make it Asnyc
Well synchronously calling SMTP servers always introduce more delay. And since I'm simply using Java SE, no fancy EE stuff. What I am thinking about is initializing a new thread for sending the mail, however, things get much more complicated when I actually want to send the response from the mail server to web client to confirm mail is being processed by mail server, as I'll have to wait for thread to get a response.
Kinda confused right now, can anyone kindly offer suggestions on how I can do it with Java SE?
Server: Ubuntu Server 12.04

Java SE offers concurrency functionality for delegating work into seperate threads see java tutorial

Related

can I send an email through a PHP mailer with my localhost without Gmail?

can I send an email through a PHP mailer with my localhost without using Gmail? or any other email service like Hotmail, outlook using my localhost?
Yes, and this is actually the best way to send using PHPMailer. There are two things you need:
A hosting provider that permits outbound SMTP. A large number of providers block SMTP by default, but you may find that they will remove the block on request (scaleway.com), provide an alternative service (AWS), which may also be acceptable.
A locally installed mail server. If you're on Linux, something like postfix is a good choice.
The way it then works is this:
Write your PHPMailer script as normal, but delivering to localhost over SMTP (not via mail())
Configure your mail server to act as a "full" mail server, where it attempts to deliver messages directly, or to act as a "smarthost" to relay through some other service, such as gmail or mailgun.
The main advantages of this approach are:
Perceived performance: your message submissions will appear to be instant, so it's great for things like contact forms
Reliability: if your message can't be delivered immediately, the local mail server will automatically take care of queuing and redelivery attempts, in a way that is far more efficient than you would ever achieve if you handled that within your own application.
As with many things, with great power comes great responsibility, and you will have to deal with bounce handling, blacklisting, inbound filtering (or just block it), etc. It's probably not worth doing all this for a simple contact form, but if you have an application that generates a reasonable amount of email traffic (signups, password resets, notifications, etc), it's a great way to go.

Whats The Key Diffrence Between Request-Response and Push-Pull Service Model In Terms Of Network Or Website Application?

Recently I did Start To Learn Node.js abd As of That i did Figure out that nower day`s node.js is widely use cause it supports Push-Pull/Publish-subscript as well as Request-Response both kind of Programming Capability.
But After Reading 6 to 8 article still i have confusion on the diffrance between them.
Any Help Would Be Appriciated.
Thanks In Advance.
It is very simple.
Lets assume the server has an update for the client. For instance, the client receives a message.
In request-response, the client won't notice about that message until he will send a request to the server, using ajax or simply moving to another page (Executing Http request).
The main problem here is that the updates are not real-time/live. The client doesn't know if there are any updates for him until he make a further request.
On the other hand, in push-pull relation the sever pushes the updates to the client,
so the client informed about the message he receives live, without waiting for the next request to receive the update.
Pull technology vs Push technology technologies explained in wikipedia.

protocol comparison for notification server with node.js

I'd like to implement push notification server using node.js. The basic scenario is:
Some applications sends notification messages to the server.
Notification server receives the request and forwards the message to uesr's mail or IM client based on user's preference.
In step 1, which protocol (e.g. REST, socket, HTTP/XML and so on.) would you recommend from the performance perspective?
Also in step 2, I have a plan to use node-xmpp module for IM client but for mail, which way is the best to implement? For example,
Just use SMTP. (But I think this might occur performance degradation because SMTP is an expensive communication and performance depends on SMTP server capacity.
use queue mechanism, in order to avoid drawbacks from the above. node.js app simply puts the message into the queue, and smtp server pulls the message.
other solutions...
Thanks in advance.
With regards to what to use as a protocol, i would go for a REST interface, whereby the application posting sends a POST request to a resource associated with the USER. something along the lines of "http://example.com/rest/v1/{userID}/notifications
I personally would use json as the data/content of the rest request and have node.js write this information to a message queue. (as a json string).
You can than have xmpp readers for each user, as well as an SMTP handler reading from this queue as fast as the SMTP server allows it to go.
However, this full post is what i would do in your situation, rather than a factual response on what is best. I know JMS fairly well and i've been working a lot with rest interfaces lately, therefore this is the way i would do it.

GUI and Threads in a chat program

Hello guys ive been searching for an answer to this question and was unable to find a suiting solution to my problem.
i have a chat program that has a somewhat advanced gui. The chat program in total consists of two programs a server and a client. ive created a protocol that my clients listens to and reacts depending on what type information it gets.
i have created a class called clientReciver which extends Thread. but i am now confused on how i will get the informaiton that the thread recives and use it in my gui.
and example of this could be how will i get the text that one of my clients sends and add it to my GUI?
It may be worth mentioning that i am using JavaFx Scenebuilder to build my GUI.
Hope someone is able to help be
Best Regards Marc Rasmussen
Hard to advise without details on your custom protocol. See the zenjava blog for some inspiration.
Use a Task to invoke your server from your client. If the result of the client server call is synchronous get the value returned by the call when the task completes. If the call is asynchronous or the server pushes data to the client, set up a listener on the client running in it's own thread and when it gets a result invoke Platform.runLater to feed the result to the JavaFX application thread for UI processing.

monitoring an email address

I'm hoping for an event based way to know when I get an email. Right now I'm using gmail but the email host isn't critical. Do I really have to poll it?
You could forward the mail to a *nix host that uses .forward files, then pipe the mail to a script that handles raising the event in your program (by pinging a URL, etc.)
Here's an example in a CPanel/PHP environment: http://kb.siteground.com/article/How_to_pipe_an_email_to_a_PHP_script.html
If you connect to gmail using IMAP, you should be able to use the IDLE command. Gmail's IMAP server does support IDLE.
RFC 5465 proposes a NOTIFY extension to IMAP. It is unlikely that many servers implement it, though.
I've had bad luck with IDLE on both GMAIL and on Dreamhost (which uses courier). Exchange does a great job with IDLE though: I see mailbox updates in less than a second.
Without good IDLE support, yes, you need to poll.

Resources