gpt4 book ai didi

javascript - 如何在java邮件中发送html按钮点击链接?

转载 作者:行者123 更新时间:2023-11-30 06:47:30 24 4
gpt4 key购买 nike

在我的代码中,我向用户发送重置密码邮件,现在我想在邮件中发送一些 html 内容,我想要一个用户单击的按钮,然后在新选项卡中打开重置密码链接,但我不这样做知道如何在 html 按钮上嵌入链接,我的链接保存在变量 token 中这是我的代码

MailService.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);
}

最佳答案

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

 var varificetioncode = 'how-to-send-link-on-html-button-click-in-java-mail';
var token = "http://stackoverflow.com/questions/43445571/"+varificetioncode;
message.setContent("<h2>Reset password request </h2>" +
"<h3> Plaese click on the button to reset password \n </h3> "+
" <a target='_blank' href="+token+"><button>Reset your password</button></a>","text/html; charset=utf-8");

关于javascript - 如何在java邮件中发送html按钮点击链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43445571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com