wrkbrs
[Java] JavaMailSenderImpl 메일 전송 내용 HTML 적용 본문
I have to send an email having all content in html that can be displayed in email as a HTML. I am able to send the email with JavaMailSenderImpl
of Spring Framework with SimpleMailMessage
but the email I send is displayed in plain html text like following
<html><body><h1>Hello</h1></body></html>
and not in form of HTML page.
Please tell the way how can i send it as HTML and how it can be displayed in form of HTML.
If you are using java mail directly, you need to set the content type to html using the setContent()method. MimeMessage.setContent("<html> <body><h1>Hello </h1> </body></html>", "text/html");
Or if you are using Spring framework's MimeMessageHelper you can use MimeMessageHelper.setText(emailContent,true) method. The boolean true
flag indicates html content. For instance:
mimeMessageHelper.setTo("some@someone");
mimeMessageHelper.setReplyTo("some@someone");
mimeMessageHelper.setFrom("some@someone");
mimeMessageHelper.setSubject("someSubject");
mimeMessageHelper.setText("<html> <body><h1>Hello </h1> </body></html>",true);
https://stackoverflow.com/questions/8652055/sending-email-content-in-html
'Java' 카테고리의 다른 글
이클립스 단축키 (0) | 2019.07.16 |
---|---|
[Eclipse] What's in an Eclipse .classpath/.project file? (0) | 2019.07.11 |
정규표현식 (Regex) 정리 / 표현식들 뜻 정리 (0) | 2019.01.11 |
[JAVA] [TIP] 정규표현식(Pattern Matching) 완전 정리! (0) | 2019.01.11 |
[JAVA] 파일삭제 File delete() 사용법 (0) | 2018.11.20 |