如何通过单击JavaFX中的链接确认用户
我试图通过JavaFX通过电子邮件发送的链接确认用户。然而,我不确定这是否可行,我愿意听取关于如何做到这一点的其他建议 对于某些背景环境:我们正在尝试在健身应用程序中为用户注册组/目标通知。管理员将发送用户加入其组的请求。用户将收到一封邮件,用户将单击链接返回到应用程序,然后接受邀请如何通过单击JavaFX中的链接确认用户,java,email,Java,Email,我试图通过JavaFX通过电子邮件发送的链接确认用户。然而,我不确定这是否可行,我愿意听取关于如何做到这一点的其他建议 对于某些背景环境:我们正在尝试在健身应用程序中为用户注册组/目标通知。管理员将发送用户加入其组的请求。用户将收到一封邮件,用户将单击链接返回到应用程序,然后接受邀请 import java.io.File; import java.util.*; import javax.mail.*; import javax.mail.internet.*;
import java.io.File;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.awt.Desktop;
import java.net.URI;
public class SendMail {
public static void sendMail(String receipient, String groupName) throws MessagingException {
String appSender = "team1.5healthtracker@gmail.com";
String password = "ganttsucks123";
//String Usersender=User.INSTANCE.getEmail();
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//get Session
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(appSender, password);
}
});
//compose message
Message message = prepareMessage(session, appSender, receipient, groupName);
Transport.send(message);
}
private static Message prepareMessage(Session session, String appSender, String receipient,String groupName){
try{
//String groupMessage="<h1> Invitation to join group </h1> <p> You are invited to join the group of <p1> "+ User.INSTANCE.getUsername()+"<p1> If you wish to join the group kindly click <a>Yes</a>. If not don't click anythting and ignore the message</p1>";
Message message = new MimeMessage(session); //Create a message object
message.setFrom(new InternetAddress(appSender)); //Set the sender
message.setRecipient(Message.RecipientType.TO, new InternetAddress(receipient)); //Set the recepient
message.setSubject("Invitation to "+ User.INSTANCE.getUsername()+"'s Group"); //Create the subject
//message.setContent(message, groupMessage);
//message.setText("You are invited to join "+ User.INSTANCE.getUsername()+"'s Group"+" called: " +groupName+" If you accept to join please send a reply to this mail, confirming so other wise ignore this message"); //Create the message
// Send the actual HTML message, as big as you like
message.setContent(
"<h1> Invitation to join group </h1> <p1> You are invited to join the group of </p1> "+ User.INSTANCE.getUsername()+" namely: " + groupName + " If you wish to join the group kindly click <a href='confirmation.html'>Yes</a>. If not don't click anythting and ignore the message</p1></h1>",
"text/html");
System.out.println("Email has been sent successfully");
System.out.println(message.getReplyTo().toString());
return message;
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
/*
public static boolean ConfirmEmail(Session session, String[] appSender, String receipient,String groupName) throws MessagingException {
Message message = new MimeMessage(session); //Create a message object
Desktop d =Desktop.getDesktop();
d.browse(new URI());
}
*/
}
导入java.io.File;
导入java.util.*;
导入javax.mail.*;
导入javax.mail.internet.*;
导入javax.activation.*;
导入java.awt.Desktop;
导入java.net.URI;
公共类SendMail{
publicstaticvoidsendmail(stringreceipent,stringgroupname)抛出MessaginException{
String appSender=“team1。5healthtracker@gmail.com";
字符串password=“gantsucks123”;
//字符串Usersender=User.INSTANCE.getEmail();
Properties props=新属性();
put(“mail.smtp.host”、“smtp.gmail.com”);
props.put(“mail.smtp.socketFactory.port”,“465”);
props.put(“mail.smtp.socketFactory.class”,
“javax.net.ssl.SSLSocketFactory”);
props.put(“mail.smtp.auth”,“true”);
props.put(“mail.smtp.port”,“465”);
//获取会话
Session Session=Session.getDefaultInstance(props,
新的javax.mail.Authenticator(){
受保护的密码身份验证getPasswordAuthentication(){
返回新的PasswordAuthentication(appSender,password);
}
});
//撰写信息
Message Message=prepareMessage(会话、应用发送者、接收者、组名);
传输。发送(消息);
}
专用静态消息prepareMessage(会话会话、字符串appSender、字符串receipient、字符串groupName){
试一试{
//String groupMessage=“加入组的邀请您被邀请加入“+User.INSTANCE.getUsername()+”的组,如果您希望加入该组,请单击。如果不愿意,请不要单击任何内容并忽略该消息”,
“文本/html”);
System.out.println(“电子邮件已成功发送”);
System.out.println(message.getReplyTo().toString());
返回消息;
}捕获(例外情况除外){
例如printStackTrace();
}
返回null;
}
/*
公共静态布尔确认邮件(会话会话会话,字符串[]appSender,字符串receipient,字符串groupName)抛出MessaginException{
Message Message=new mimessage(会话);//创建消息对象
Desktop d=Desktop.getDesktop();
d、 浏览(新URI());
}
*/
}
我认为你可以在数据库中使用它(没有足够的代表评论sry)看不到与javafx的任何关系,所以删除了标签(请随时重新添加,并详细解释它的关系:)你应该尽快更改你的gmail帐户密码