发送电子邮件的程序[J2EE]
import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; /** 来 自 时 代 J a v a 公 众 号 - nowjava.com **/ public class SendApp { public static void send(String smtpHost, int smtpPort, String from, String to, String subject, String content) throws AddressException, MessagingException { java.util.Properties props = new java.util.Properties(); props.put("mail.smtp.host", smtpHost); props.put("mail.smtp.port", ""+smtpPort); Session session = Session.getDefaultInstance(props, null); // Construct the message Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(from)); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); msg.setSubject(subject);/** 来自 n o w j a v a . c o m - 时代Java**/ msg.setText(content); // Send the message Transport.send(msg); } public static void main(