2023年3月9日18:09:41
parent
71aece0cbf
commit
708c7c4c82
|
|
@ -434,4 +434,9 @@ public class HomeController implements Serializable {
|
|||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void mail_menu_item(ActionEvent event) {
|
||||
load_small_tools(7);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.extra.mail.MailUtil;
|
||||
import cn.hutool.setting.Setting;
|
||||
import com.zhangmeng.tools.utils.AlertUtils;
|
||||
import com.zhangmeng.tools.utils.ImagePath;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-03-09 16:24
|
||||
*/
|
||||
@Slf4j
|
||||
public class MailController {
|
||||
|
||||
@FXML
|
||||
public TextField host;
|
||||
|
||||
@FXML
|
||||
public TextField port;
|
||||
|
||||
@FXML
|
||||
public TextField from;
|
||||
|
||||
@FXML
|
||||
public TextField user;
|
||||
|
||||
@FXML
|
||||
public TextField pass;
|
||||
|
||||
@FXML
|
||||
public TextArea content;
|
||||
|
||||
@FXML
|
||||
public Button send;
|
||||
|
||||
@FXML
|
||||
public ListView<String> user_list;
|
||||
|
||||
@FXML
|
||||
public TextField to;
|
||||
|
||||
@FXML
|
||||
public Button add_user_to;
|
||||
|
||||
@FXML
|
||||
public TextField file_path;
|
||||
|
||||
@FXML
|
||||
public Button choose_file;
|
||||
|
||||
public static int mail_port = 25;
|
||||
|
||||
public ObservableList<String> list = FXCollections.observableArrayList();
|
||||
|
||||
public static final String p = "smtp";
|
||||
|
||||
private final Setting setting = new Setting("config/mail.setting");
|
||||
|
||||
private SimpleObjectProperty<File> file_info = new SimpleObjectProperty<>();
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
choose_file.setText(null);
|
||||
ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE)));
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(18);
|
||||
choose_file.setGraphic(iv);
|
||||
|
||||
choose_file.setOnAction(event -> {
|
||||
Stage stage = new Stage();
|
||||
FileChooser fc = new FileChooser();
|
||||
fc.setTitle("单选文件");
|
||||
fc.getExtensionFilters().addAll(
|
||||
new FileChooser.ExtensionFilter("所有类型", "*.*")
|
||||
);
|
||||
|
||||
File file = fc.showOpenDialog(stage);
|
||||
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
file_info.setValue(file);
|
||||
});
|
||||
|
||||
setting.autoLoad(true);
|
||||
String main_host = setting.get("host");
|
||||
String main_port = setting.get("port");
|
||||
String main_from = setting.get("from");
|
||||
String main_user = setting.get("user");
|
||||
String main_pass = setting.get("pass");
|
||||
|
||||
if (main_host != null && main_host.length() != 0){
|
||||
host.setText(main_host);
|
||||
}
|
||||
|
||||
if (main_port != null && main_port.length() != 0){
|
||||
port.setText(main_port);
|
||||
}
|
||||
|
||||
if (main_from != null && main_from.length() != 0){
|
||||
from.setText(main_from);
|
||||
}
|
||||
|
||||
if (main_user != null && main_user.length() != 0){
|
||||
user.setText(main_user);
|
||||
}
|
||||
|
||||
if (main_pass != null && main_pass.length() != 0){
|
||||
pass.setText(main_pass);
|
||||
}
|
||||
|
||||
//设置端口默认
|
||||
if (port.getText().length() == 0){
|
||||
port.setText(String.valueOf(MailController.mail_port));
|
||||
}
|
||||
|
||||
user_list.setFixedCellSize(40);
|
||||
user_list.setItems(list);
|
||||
user_list.setPlaceholder(new Label("暂无发送人!"));
|
||||
|
||||
from.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue != null){
|
||||
host.setText(p + "." + newValue.split("@")[1]);
|
||||
user.setText(newValue.split("@")[0]);
|
||||
}
|
||||
});
|
||||
|
||||
send.setOnAction(event -> {
|
||||
|
||||
if (from.getText().length() == 0 ){
|
||||
AlertUtils.alert_warning("发件人不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (pass.getText().length() == 0 ){
|
||||
AlertUtils.alert_warning("发件人密码不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (host.getText().length() == 0 ){
|
||||
host.setText(p + "." + from.getText().split("@")[1]);
|
||||
}
|
||||
|
||||
if (port.getText().length() == 0){
|
||||
user.setText(from.getText().split("@")[0]);
|
||||
}
|
||||
save_config();
|
||||
|
||||
//判断附件是否为空
|
||||
|
||||
});
|
||||
|
||||
choose_file.setOnAction(event -> {
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void save_config(){
|
||||
save("host",host.getText());
|
||||
save("port",port.getText());
|
||||
}
|
||||
|
||||
private void save(String key,String value){
|
||||
setting.set(key,value);
|
||||
String settingPath = setting.getSettingPath();
|
||||
setting.store(settingPath);
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ import javafx.beans.value.ChangeListener;
|
|||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Pos;
|
||||
|
|
@ -72,6 +73,7 @@ public class SmallToolsController {
|
|||
private AnchorPane qr_code;
|
||||
private AnchorPane date_query;
|
||||
private AnchorPane cron;
|
||||
private AnchorPane mail;
|
||||
|
||||
@FXML
|
||||
private ListView<ResourcesUtils.SmallTools> listView;
|
||||
|
|
@ -335,6 +337,13 @@ public class SmallToolsController {
|
|||
}
|
||||
cron(flag);
|
||||
}
|
||||
|
||||
if (newValue.getIndex() == 7) {
|
||||
if (mail != null) {
|
||||
flag = true;
|
||||
}
|
||||
mail(flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -348,6 +357,7 @@ public class SmallToolsController {
|
|||
case Qr_CODE -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE));
|
||||
case Date_Query -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE));
|
||||
case Cron -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE));
|
||||
case Mail -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE));
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -559,4 +569,30 @@ public class SmallToolsController {
|
|||
log.info("newValue.doubleValue():{}", newValue.doubleValue());
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void mail_menu_item(ActionEvent event) {
|
||||
boolean flag = false;
|
||||
if (mail != null){
|
||||
flag = true;
|
||||
}
|
||||
mail(flag);
|
||||
}
|
||||
|
||||
private void mail(boolean flag ){
|
||||
//默认选择第一个
|
||||
listView.getSelectionModel().select(7);
|
||||
|
||||
if (!flag) {
|
||||
try {
|
||||
root = FXMLLoader.load(ResourcesUtils.getResource("mail"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mail = root;
|
||||
} else {
|
||||
root = mail;
|
||||
}
|
||||
common_method();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,6 @@ public class ResourcesUtils {
|
|||
}
|
||||
|
||||
public enum SmallTools{
|
||||
|
||||
Hex_16("16进制(Hex)",0),
|
||||
Unicode("Unicode和字符串转换",1),
|
||||
JWT_WEB("json-web-token",2),
|
||||
|
|
@ -118,6 +117,7 @@ public class ResourcesUtils {
|
|||
Qr_CODE("生成二维码",4),
|
||||
Date_Query("日历",5),
|
||||
Cron("cron表达式",6),
|
||||
Mail("发送邮件",7),
|
||||
;
|
||||
|
||||
SmallTools(String title, int index) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
<MenuItem mnemonicParsing="false" text="二维码生成" onAction="#qr_code_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="时间工具" onAction="#date_query_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="cron表达式" onAction="#cron_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="邮件发送" onAction="#mail_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane fx:controller="com.zhangmeng.tools.controller.MailController" prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
|
||||
<children>
|
||||
<Label layoutX="33.0" layoutY="46.0" text="邮件服务器的SMTP地址:" />
|
||||
<TextField fx:id="host" layoutX="171.0" layoutY="42.0" prefHeight="25.0" prefWidth="285.0" />
|
||||
<Label layoutX="33.0" layoutY="106.0" text="邮件服务器的SMTP端口:" />
|
||||
<TextField fx:id="port" layoutX="171.0" layoutY="102.0" prefHeight="25.0" prefWidth="285.0" />
|
||||
<TextField fx:id="from" layoutX="171.0" layoutY="159.0" prefHeight="25.0" prefWidth="285.0" />
|
||||
<TextField fx:id="user" layoutX="171.0" layoutY="211.0" prefHeight="25.0" prefWidth="285.0" />
|
||||
<Label layoutX="126.0" layoutY="163.0" text="发件人:" />
|
||||
<Label layoutX="126.0" layoutY="215.0" text="用户名:" />
|
||||
<Label layoutX="138.0" layoutY="264.0" text="密码:" />
|
||||
<TextField fx:id="pass" layoutX="171.0" layoutY="260.0" prefHeight="25.0" prefWidth="285.0" />
|
||||
<Text layoutX="471.0" layoutY="59.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(可选,默认为smtp.<发件人邮箱后缀>)" />
|
||||
<Text layoutX="471.0" layoutY="119.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(可选,默认25)" />
|
||||
<Text layoutX="471.0" layoutY="176.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(必须正确,否则发送失败)" />
|
||||
<Text layoutX="471.0" layoutY="277.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(注意,某些邮箱需要为SMTP服务单独设置授权码)" />
|
||||
<Text layoutX="471.0" layoutY="228.0" strokeType="OUTSIDE" strokeWidth="0.0" text="(默认为发件人邮箱前缀)" />
|
||||
<Label layoutX="138.0" layoutY="319.0" text="内容:" />
|
||||
<TextArea fx:id="content" layoutX="171.0" layoutY="328.0" prefHeight="178.0" prefWidth="940.0" AnchorPane.bottomAnchor="151.0" AnchorPane.leftAnchor="171.0" AnchorPane.rightAnchor="89.0" AnchorPane.topAnchor="320.0" />
|
||||
<Button fx:id="send" layoutX="276.0" layoutY="565.0" mnemonicParsing="false" text="发送" AnchorPane.bottomAnchor="59.0" />
|
||||
<Label layoutX="752.0" layoutY="46.0" text="发送人列表:" />
|
||||
<ListView fx:id="user_list" layoutX="826.0" layoutY="40.0" prefHeight="149.0" prefWidth="285.0" AnchorPane.leftAnchor="826.0" AnchorPane.rightAnchor="89.0" AnchorPane.topAnchor="40.0" />
|
||||
<Label layoutX="752.0" layoutY="215.0" text="发送人邮箱:" />
|
||||
<TextField fx:id="to" layoutX="826.0" layoutY="211.0" prefHeight="25.0" prefWidth="285.0" AnchorPane.leftAnchor="826.0" AnchorPane.rightAnchor="89.0" />
|
||||
<Button fx:id="add_user_to" layoutX="941.0" layoutY="260.0" mnemonicParsing="false" text="添加" />
|
||||
<Label layoutX="130.0" layoutY="513.0" text="附件:" AnchorPane.bottomAnchor="119.0" />
|
||||
<TextField fx:id="file_path" layoutX="233.0" layoutY="509.0" prefHeight="25.0" prefWidth="330.0" AnchorPane.bottomAnchor="115.0" AnchorPane.leftAnchor="233.0" AnchorPane.rightAnchor="637.0" />
|
||||
<Button fx:id="choose_file" layoutX="171.0" layoutY="509.0" mnemonicParsing="false" text="Button" AnchorPane.bottomAnchor="115.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
|
@ -36,6 +36,7 @@
|
|||
<MenuItem mnemonicParsing="false" text="二维码生成" onAction="#qr_code_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="时间工具" onAction="#date_query_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="cron表达式" onAction="#cron_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="邮件发送" onAction="#mail_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue