|
|
@@ -9,15 +9,22 @@ import javax.mail.internet.MimeMessage;
|
|
|
import java.util.Properties;
|
|
|
|
|
|
public class EmailSender {
|
|
|
- public static void main(String[] args) {
|
|
|
+
|
|
|
+ public Boolean sendLocalMail(String toMail, String fromMail, String hostIp, String subject, String text) {
|
|
|
+ toMail = "pm@192.168.1.127";
|
|
|
+ fromMail = "cgj@192.168.1.127";
|
|
|
+ hostIp = "192.168.1.127";
|
|
|
+ subject = "今天的主题";
|
|
|
+ text = "今天的天气真不错";
|
|
|
+
|
|
|
// 收件人邮箱地址
|
|
|
- String to = "pm@192.168.1.127";
|
|
|
+ String to = toMail;
|
|
|
|
|
|
// 发件人邮箱地址
|
|
|
- String from = "cgj@192.168.1.127";
|
|
|
+ String from = fromMail;
|
|
|
|
|
|
// SMTP服务器地址(HMailServer的地址)
|
|
|
- String host = "192.168.1.127"; // 或者你的HMailServer的IP地址或域名
|
|
|
+ String host = hostIp; // 或者你的HMailServer的IP地址或域名
|
|
|
|
|
|
// 获取系统属性
|
|
|
Properties properties = System.getProperties();
|
|
|
@@ -41,16 +48,17 @@ public class EmailSender {
|
|
|
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
|
|
|
|
|
|
// 设置邮件主题
|
|
|
- message.setSubject("This is the Subject Line!");
|
|
|
+ message.setSubject(subject);
|
|
|
|
|
|
// 设置邮件内容
|
|
|
- message.setText("今年天气真好");
|
|
|
+ message.setText(text);
|
|
|
|
|
|
// 发送消息
|
|
|
Transport.send(message);
|
|
|
- System.out.println("Sent message successfully....");
|
|
|
+ return true;
|
|
|
} catch (MessagingException mex) {
|
|
|
mex.printStackTrace();
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|