简体   繁体   English

在电子邮件中发送验证码链接

[英]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? 此处添加参数的示例如何将url参数添加到当前url? ; ;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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