0

I'm new in programming. How am I going to send A verification link in email?

I managed to send Email but not A verification code, that a user must click in order to complete the registration. thanks in advance.

Here is the code in sending mail.

public static void send() {
        String to = "rchiluano@partnersolutions.com.ph";//change accordingly
        String from = "hryanmark@gmail.com";//change accordingly


   String host = "localhost";//or IP address


    //Get the session object
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(properties);


    //compose the message
    try{
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
        message.setSubject("Verify your Account");
        message.setText("\tWe receive your request for registration. \n \n 
        \tPlease click the Link below to complete the registration\n" +
                "");


        // Send message
        Transport.send(message);
        System.out.println("Sent");

    }catch (MessagingException mex) {mex.printStackTrace();}

}
Kuya
  • 28
  • 11
  • Possible duplicate of [how to verify user clicked on link in email that I sent him/her?](https://stackoverflow.com/questions/10545507/how-to-verify-user-clicked-on-link-in-email-that-i-sent-him-her) – vinS Dec 20 '17 at 06:22
  • @vinS hmm I'd like to know on how to send a "link" in email since I only sent a plaint text. – Kuya Dec 20 '17 at 06:36
  • @Kuya You need to give HTML instead of plain text in order to send a mail. I am not a java guy but looking at the code something like `message.setSubject("Verify your Account. Click here");` – abhinav Dec 20 '17 at 06:38
  • So your question is that you do not know how to make correspondence between your link and user or you do not know how to make link clickable by user ? – Uta Alexandru Dec 20 '17 at 06:44
  • @UTA I do not know how to make make correspondence between your link and user . sorry I edited the first reply – Kuya Dec 20 '17 at 07:23

2 Answers2

0

You need to add a parameter to your link with a unique indentifier on it(a random+current date ... or i do not know your choose).Also u need to store that random in your database corresponding to your user in your user table.And when the page its opened u will simply update a column in your database which tracks if user have activate his account corresponding to the unique identifier which comes from that link . An example here of adding params How to add url parameter to the current url? ;

Uta Alexandru
  • 324
  • 4
  • 11
0

You need to add a parameter to your link with a unique identifier on it(a random+current date ... or I do not know your choice).Also, u need to store that random in your database corresponding to your user in your user table

D S
  • 258
  • 9
  • 25