如何在java邮件中点击html按钮点击链接?

时间:2017-04-17 05:20:06

标签: javascript java html email

在我的代码中,我向用户发送重置密码邮件,现在我想在邮件中发送一些html内容,我想要一个用户点击的按钮,然后重置密码链接在新标签页中打开,但我没有&#39 ;知道如何在html按钮上嵌入链接,我的链接保存在变量token中 这是我的代码

MailServiice.java

public void sendMail(String email,String token)
    {
        this.email=email;
        this.token=token;
     try {
               // Create a default MimeMessage object.
               Message message = new MimeMessage(session);

               // Set From: header field of the header.
               message.setFrom(new InternetAddress(from));

               // Set To: header field of the header.
               message.setRecipients(Message.RecipientType.TO,
                       InternetAddress.parse(to));

               // Set Subject: header field
               message.setSubject("change password request");



               // Now set the actual message 
              //  message.setText(messages);
                message.setContent(
                        "<h2>Reset password request </h2>" + 
                        "<h3> Plaese click on the button to reset password \n </h3> "+
                        " <a href=token>" +"<button>Reset your password</button></a>" + token,
                        "text/html");


               // Send message
               Transport.send(message);

               System.out.println("Sent message successfully....");

              } catch (MessagingException e) {
                 throw new RuntimeException(e);
              }

1 个答案:

答案 0 :(得分:1)

我希望它会有所帮助。 我添加了Fidler

maatwebsite (laravel)