简体   繁体   中英

Sending a verification code Link in email

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();}

}

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? ;

您需要在您的链接中添加一个带有唯一标识符的参数(随机+当前日期......或者我不知道您的选择)。此外,您需要将该随机数存储在您的用户中与您的用户相对应的数据库中桌子

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM