📄 sendregconfirmationemail.java
字号:
package com.longHua.domain.logic;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import com.longHua.domain.UserReg;
public class SendRegConfirmationEmail implements InitializingBean{
private static final String DEFAULT_MAIL_FROM = "xingyuanjian@sina.com";
private static final String DEFAULT_SUBJECT = "欢迎你注册——龙华电子商务!";
private final Log logger = LogFactory.getLog(getClass());
private MailSender mailSender;
private String mailFrom = DEFAULT_MAIL_FROM;
private String subject = DEFAULT_SUBJECT;
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
public void setMailFrom(String mailFrom) {
this.mailFrom = mailFrom;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void afterPropertiesSet() throws Exception {
if (this.mailSender == null) {
throw new IllegalStateException("mailSender is required");
}
}
public void SendRegConfirmationEmailAdvice(JoinPoint joinPoint) throws Throwable {
Object[] userRegs=joinPoint.getArgs();
UserReg userReg=(UserReg)userRegs[0];
if (userReg.getUserMail() == null || userReg.getUserMail().length() == 0) {
return;
}
StringBuffer text = new StringBuffer();
text.append(userReg.getUserName()).append("你好");
text.append(",欢迎你在我们龙华电子商务注册,请确认你注册的信息,你的用户名是: ").append(userReg.getUserName()).append("<br>");
text.append("你的登陆密码是:").append(userReg.getUserPwd());
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo(userReg.getUserMail());
mailMessage.setFrom(this.mailFrom);
mailMessage.setSubject(this.subject);
mailMessage.setText(text.toString());
try {
this.mailSender.send(mailMessage);
}
catch (MailException ex) {
logger.warn("An exception occured when trying to send email", ex);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -