java设计模式应用
2021-04-07 16:26
标签:intern mail net end this com utf-8 -- private 1、builder设计模式(邮件工具类) 很高兴你给的我的回信,这给了我很多灵感。 java设计模式应用 标签:intern mail net end this com utf-8 -- private 原文地址:https://www.cnblogs.com/snow-wolf-1/p/13387533.htmlpublic class EmailMessage {
private Message message;
private static final String FROM = "sender";
private static final String PASSWORD = "****";
private static Session session;
static {
Properties properties = new Properties();
// 连接协议
properties.setProperty("mail.transport.protocol", "smtp");
// 主机名
properties.setProperty("mail.smtp.host", "smtp.qq.com");
// 端口号
properties.put("mail.smtp.port",465);
properties.setProperty("mail.smtp.auth", "true");
// 设置是否使用ssl安全连接 ---一般都使用
properties.setProperty("mail.smtp.ssl.enable", "true");
// 设置是否显示debug信息 true 会在控制台显示相关信息
properties.setProperty("mail.debug", "true");
session = Session.getInstance(properties);
}
public static void main(String[] args) throws MessagingException {
new EmailMessage
.MessageBuilder(EmailMessage.session)
.sender(EmailMessage.FROM)
.receiver("receiver")
.subject("java发送邮件")
.content("
你好,Jack