Java: how to check if a user has been clicked or responded to an email (as part of an email authentication scheme)?

I hope not to reinvent the wheel - I'm pretty new to Java, but I need a simple but reliable email check algorithm / code / software for web application users (for example, I just need help in step 4 below). That is, I need to check that the user registration has access to the email address that he provides when entering the system.

The steps that I mean for intermediate Java are as follows:

  • Java POJO receives a user email address and password from a client.
  • POJO is talking to the database server to verify that the email / password command is valid.
  • If this is true, POJO sends an email to the email address, asking the user to reply to the email (or click on some provided link, etc.).
  • POJO receives a notification (how?) To which the user replied to an email (or clicked a link, etc.).
  • POJO informs the web application of the success (or failure) of authentication, thereby allowing or denying access to the application.

I can write everything except step 4. Essentially I need a way to send an email to the user, and then get some type of response indicating that the user has received the email.

Does anyone know how to do this? If not, what do you recommend as the next best / easiest solution?

I do not use the framework since my intermediate level of Java is very simple. I would like the solution to be scarce (which means you don't want to install / deploy more than I need, Spring seems redundant). I read Shiro but found no evidence supporting email authentication. Any advice is greatly appreciated to help me avoid writing unnecessary / unproven procedures.

+4
source share
2 answers

The easiest way is to have a code that connects to the mailbox of the destination address using POP3 or IMAP and waits for new incoming messages.

When sending an email, you can add a Message-ID header. When the user replies to the email, there will be References , which must have a message identifier, which the user also responds.

When you can use this identifier to correlate what they are responding to.

For security reasons, you may want to embed an identifier in the message itself (since most people do not edit the replies today), so you can view the body of the message if for some reason the Reference header is not supplied. There are other methods to give each mail an address client-client response, which is another way to do this, but this requires mail server support.

But, in any case, as soon as you figure out the structure of messages, you just listen to the mailbox of the address and look for new messages. As they arrive, your bar contains message identifiers and marks them as appropriate in the database or something else.

As for the β€œwaiting” message, you should understand that it can be a long wait. Instead of waiting for a POJO, rather, there is a simple process that checks the status. You may have a timer that fires every second and then checks the database to see if it is updated, etc. Obviously, this is what you want to undo.

For all mail needs, you can use JavaMail - it does all of this, and it's pretty simple to use.

+2
source

There are two controllers involved (two POJOs).

the first connection, for steps 1,2 + 3 - one object on the server. as part of (2), a unique code (the UUID mentioned in the comments) is generated and stored in the database.

the second connection, when the user clicks on the link, switches to another controller (another POJO, which may be the same class or may be a different class, depending on your implementation). which reads the UUID from the link, goes to the database, finds the email associated with the UUID, and marks the email as confirmed.

update I'm struggling to understand what you are missing, but when the user clicks on the link in the letter, the operating system opens a web browser. The web browser establishes a connection to the server. the server receives an HTTP GET request with the UUID in the URL and passes the UUID to the POJO.

several terms: the process of processing an incoming request in a web server is usually called "routing", and the general template used to structure the code called "MVC". the exact details will depend on the application structure used. for Java code on servlets, there is a mapping of URLs to servlets (servlets are Java code that implements a certain interface), the infrastructure can provide a servlet that ultimately causes you to call POJO, or you can write a servlet yourself, and in this case it will be your POJO, although in this case it is the wrong word, because it implements a certain interface) in the web.xml file.

also, I think the client web browser uses TCP to establish a connection over the network (it is almost always over IP because you use the Internet). In addition, the client "speaks" the message in HTTP. all of these different layers are described in the osi-level 7 network model.

there is a huge amount of detail at so many levels. hope you get started.

see also http://www.quora.com/What-happens-when-you-type-a-URL-into-your-browser

+2
source

All Articles