JMail

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");
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值