Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从java REST服务发送验证代码/链接_Java_Rest_Email_Smtp_Dropwizard - Fatal编程技术网

从java REST服务发送验证代码/链接

从java REST服务发送验证代码/链接,java,rest,email,smtp,dropwizard,Java,Rest,Email,Smtp,Dropwizard,我有一个dropwizard REST服务,我试图在用户注册后实现发送验证电子邮件链接/代码 在用户表中,我的数据库中有一个名为is_active的字段,表示是否验证了用户 private String email; @JsonProperty private String password; @JsonProperty private String name; @JsonProperty private String surname; @JsonProperty

我有一个dropwizard REST服务,我试图在用户注册后实现发送验证电子邮件链接/代码

在用户表中,我的数据库中有一个名为is_active的字段,表示是否验证了用户

  private String email;
  @JsonProperty
  private String password;
  @JsonProperty
  private String name;
  @JsonProperty
  private String surname;
  @JsonProperty
  private boolean isActive;

我正在尝试找出发送此验证电子邮件的正确方式,我编写了一个类,可以向用户发送SMTP电子邮件,但我对其发送电子邮件的正确方式是否有点怀疑

public class SendEmail  
{  
 public static void main(String [] args){  
      String to = "customer@gmail.com";
      String from = "mycompany@gmail.com";  
      String host = "localhost";

      Properties properties = System.getProperties();  
      properties.setProperty("mail.smtp.host", host);  
      Session session = Session.getDefaultInstance(properties);  
      try{  
         MimeMessage message = new MimeMessage(session);  
         message.setFrom(new InternetAddress(from));  
         message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
         message.setSubject("verification email");  
         message.setText("Hello, this is sample verification email ");  

         Transport.send(message);  
         System.out.println("message sent successfully....");  

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

这就是我应该如何实现或使用类似的外部提供者的方法吗?

您的方法很好。需要考虑的一些事项:

  • SMTP服务器在哪个时间段内接受多少封电子邮件?某些SMPT服务器应用可能导致消息发送失败的速率限制。您的代码应该认识到这一点,并且有一个策略,可以在以后重新发送电子邮件
  • 电子邮件正文中的验证链接应包含唯一的机密,该机密只能用于验证特定用户。此机密必须存储并与用户关联
  • 该链接不应包含诸如用户ID或名称之类的内容。这种链接很容易伪造
  • 通过单击验证链接调用的RESTAPI应该获取该秘密并查找与其关联的用户

    • 你的方法很好。需要考虑的一些事项:

      • SMTP服务器在哪个时间段内接受多少封电子邮件?某些SMPT服务器应用可能导致消息发送失败的速率限制。您的代码应该认识到这一点,并且有一个策略,可以在以后重新发送电子邮件
      • 电子邮件正文中的验证链接应包含唯一的机密,该机密只能用于验证特定用户。此机密必须存储并与用户关联
      • 该链接不应包含诸如用户ID或名称之类的内容。这种链接很容易伪造
      • 通过单击验证链接调用的RESTAPI应该获取该秘密并查找与其关联的用户