SendMail themail = new SendMail("smtp.263xmail.com");//发送邮件的服务器
themail.setNeedAuth(true);
//设置主题
themail.setSubject("Retrieve password");//设置邮件内容
themail.setBody("Your new password is:\n"+rndString+"\n Please change your password after you log in!");
//设置收件人Email地址
.setTo(accEmail);
//设置发件人Eamil地址
themail.setFrom("[email protected]");
//设置发件人Email的用户名和密码
themail.setNamePass("[email protected]", "zggykjigctoc");
//判断是否有发送出去
if (themail.sendout() == false) {
System.out.println("The email send failure!");
request.setAttribute("msg","The email send fails!");
}else{
//System.out.println("getBackUserPwd------------");
AccService.updatePws(accPSW, accID);
request.setAttribute("msg", "your password has already sent to your mail box");
}
解决方案 »
- 请教出错原因,在线等 谢谢
- ★★★★log4j多线程写同一个文件,log丢失★★★
- 谁能给我解释一下这个方法 查询页数的
- myeclipse5.1+struts1.2+tomcat5.5+ie7,的jsp页面缓存问题!
- hibernate出错,Exception in thread "main" org.hibernate.MappingException: Unknown entity: dd.Person
- spring和json rpc如何整合在一起?
- 能用javac编译但用java命令运行时报告Exception in thread "main" java.lang.NoClassDefFoundError: h
- STRUTS问题,这个是不是错误
- 为什么我的APPLET程序在网页只显示个灰框?
- 请问在PetStore里面,SessionBean里面都有一些类似于shoppingCartEJB_56rmz5_Impl.class这样的类,继承了EJB的实现类,有不有哪们高手知
- Struts的bean:message问题
- 在struts里用EL表达式和C标签好么
I had resolved this question!import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*; public class SendMail {
public SendMail() {
}
public static void main(String []args)
{
try
{ Properties mailProps = new Properties();
mailProps.put("mail.smtp.host","smtp.163.com");
mailProps.put("mail.smtp.auth", "true");
mailProps.put("username","qxwtt");
mailProps.put("password","7405130");
Session mailSession = Session.getInstance(mailProps, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("qxwtt",
"7405130");
}
});
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipient(Message.RecipientType.TO,new InternetAddress("[email protected]"));
message.setSubject("Mail Test");
MimeMultipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText("Hello World!");
multi.addBodyPart(textBodyPart);
message.setContent(multi);
message.saveChanges();
Transport.send(message);
}
catch (Exception ex)
{
System.err.println("邮件发送失败的原因是:"+ex.getMessage());
System.err.println("具体错误原因:");
ex.printStackTrace(System.err);
}
}
}