jsp发送E-Mail需要activation.jar 和javamail.jar两个.jar包,将其放至项目的lib目录下!
以下是源代码及在开发过程中遇到的问题和解决办法:
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EmailService {
// 默认主机;邮箱发送;下面的用户名和密码就是你sohu邮箱的username/pwd
private static final String host = "smtp.sohu.com";
// 是谁发的信息
private static final String fromEmail = "nihao919833@sohu.com";
public static void main(String[] args) {
EmailService email = new EmailService();
email.sendMess(null, "libaogang.1990@gmail.com", null, "标题", "内容");
}
/**
* 客户端调用用于发送信息
*
* @param emailToOne