public class LoginAction extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
LoginActionForm loginForm = (LoginActionForm)form;
String username = loginForm.getUsername();
String password = loginForm.getPassword();
String email = loginForm.getEmail();
System.out.println("username = " + username);
System.out.println("password = " + password);
System.out.println("email = " + email);
int port = 25;
String server = "smtp.sina.com"; // 邮件服务器(新浪)
String from = "Webmaster<eternal327@sina.com>"; // 发送者
String to = email; // 收信者
String user = "eternal327@sina.com"; // 发送者地址
String pwd = "*******"; // 密码
Properties props = new Properties();
props.put("mail.smtp.host", server);
props.put("mail.smtp.port", String.valueOf(port));
props.put("mail.smtp.auth", "true");
Transport transport = null;
Session session = Session.getDefaultInstance(props, null);
try {
transport = session.getTransport("smtp");
transport.connect(server, user, pwd);
MimeMessage msg = new MimeMessage(session);
//msg.setSentDate(new Date());
InternetAddress fromAddress = new InternetAddress(from);
msg.setFrom(fromAddress);
InternetAddress[] toAddress = new InternetAddress[1];
toAddress[0] = new InternetAddress(email);
msg.setRecipients(Message.RecipientType.TO, toAddress);
msg.setSubject("theme", "UTF-8");
msg.setText("感谢您的注册", "UTF-8");
msg.saveChanges();
transport.sendMessage(msg, msg.getAllRecipients());
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("success");
}
}
12-02

被折叠的 条评论
为什么被折叠?



