📄 sendmessage.java
字号:
package javamail;
import java.util.*;
import javax.activation.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.naming.*;
import java.util.Properties;
public class SendMessage {
private static final String url = "t3://localhost:7001";
public static void send (String to, String from, String subject, String content) throws Exception {
Properties props = new Properties();
InitialContext ic = new InitialContext();
Session session = (Session)ic.lookup("MailSession");
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(content, "text/plain");
Transport.send(msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -