我正在尝试发送一封电子邮件,其中包含otp作为内容。没有得到什么问题,内容设置为空。
public Boolean sendAdminLoginOtp(final CHEMRAdminLoginDetails details)
throws CHEMRException {
if (M_LOG.isDebugEnabled()) {
M_LOG.debug("CHEMRMailerServiceImpl.sendOtpToUserForResetPassword");
}
try {
final String fname = details.getFirstName();
final String lname = details.getLastName();
final Long otp = details.getOtp();
final String email = details.getEmail();
final Session emailSession = getEmailerSession();
final Message message = new MimeMessage(emailSession);
message.setFrom(new InternetAddress(
m_mailerBundle.getString("emrMailerUserName")));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email));
message.setSubject("noreply-Mail");
/*
* message.setContent("Hi" + details.getFirstName() + " " +
* details.getLastName() +
* ".\n\nYour OTP to Login into your account : " + details.getOtp()
* + "\n\n " + "\n\nThanks\nSupport Team", "text/plain");
*/
message.setContent( "<p>Hi " + fname +" "+ lname + ", "
+ "<br><br>Your OTP to Login into your account : " + otp
+ "<br><br>Thanks,Support Team.</p>", "text/html");
Transport.send(message);
return true;
} catch (final Exception e) {
final String[] replacmentObject = new String[] { e.getMessage() };
M_LOG.error(
"CHEMRMailerServiceImpl Failed to sendOtpToUserForResetPassword.."
+ e.getMessage());
final ErrorRecorder _errorRecorder = m_chemrServicesObjectFactory
.getErrorRecorder();
_errorRecorder.addError(CHEMRErrorCodes.EMRMAILER4001,
replacmentObject);
throw new CHEMRException("ERROR in Manager Layer ::",
_errorRecorder.getErrors());
}
}
上面的是我尝试过的代码
我经过调试,才知道内容设置为空。
以上是我得到的例外。希望有人可以帮助我