大家好,我正在做一个基于jsp的邮件收发系统,有哪位好心人可以发个源码借鉴一下,必有重谢!
邮箱号码875560133@qq.com
String username="发件邮箱账号";
String post="xtybzusnjecvbcbc";//登陆qq邮箱每次登陆,它生成的码
String registerId = "" + Math.random() * Math.random();
String url = "http://localhost:8080/loginemail/servlet/MailBackServlet?registerId=" + registerId;
HttpSession httpSession = request.getSession();
httpSession.setAttribute(registerId, name);
httpSession.setMaxInactiveInterval(600);
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "smtp.qq.com");
props.setProperty("mail.smtp.auth", "true");
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.starttls.enable", "true");
Authenticator authenticator = new MyAuthenticator(username, post);
Session session = Session.getInstance(props,authenticator);
session.setDebug(true);
try{
Address from = new InternetAddress(username);
Address to = new InternetAddress(email);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(from);
msg.setSubject("*********");
msg.setSentDate(new Date());
msg.setContent("点击<a href='" + url + "'>" + url + "</a>完成注册!", "text/html;charset=utf-8"); //发送给你邮箱里的内容
msg.setRecipient(RecipientType.TO, to);
我这个代码是邮箱验证时候的代码,你的收发邮件和这个差不多,原理都是一样的,邮箱账号的话,前台可以运用jsp文本框输入,然后跳转到这个servlet代码页面,用request取出。其实很简单,你自己好好看看吧