문제

Spring's org.springframework.mail.javamail.MimeMessageHelper.setSentDate(Date date) takes a date that will be set in the header of the email, but not a format. I need to specify a particular format.

I checked the source and MimeMessage uses javax.mail.internet.MailDateFormat to format it, but it doesn't have a way to set the format from the application.

도움이 되었습니까?

해결책

You can alternately set a custom header using the MimeMessage.addHeader(String, String) method, and insert the formatted date using SimpleDateFormat.format(Date):

String dateFormat = "yyyy-MM-dd HH:mm:ss"; // you specify the format for your date
String formattedDate = new SimpleDateFormat(dateFormat).format(new Date());
MimeMessage mimeMessage = //get message from wherever
mimeMessage.addHeader("Date", formattedDate);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top