我一直在使用jsp(spring,mvc model2)来使用jsp和javamail发送html格式的邮件。对象消息是电子邮件接收者读取的部分。我使用基本的html标签进行装饰,但我想使用CSS以便我可以更多地设计它。使用javamail发送邮件时有没有办法使用css?
这是邮件发件人控制器。
@RequestMapping(value = "/mailSender", method = RequestMethod.GET)
public String mailSender(@RequestParam(value = "mem_id", defaultValue = "") String mem_id,
@RequestParam(value = "encrypt_no", defaultValue = "") String encrypt_no,
@RequestParam(value = "occu_code", defaultValue = "0") int occu_code) throws AddressException, MessagingException {
String host = "smtp.gmail.com";
final String username = "gmailid";
final String password = "gmailpw";
int port=465;
String recipient = mem_id;
String subject = "mail title";
Object message =
"<h2><strong>HOTEL NOMAD</strong></h2><br>"
+ "<h3>reset your pw<br><br>"
+ "http://127.0.0.1:8080/team/pwReset?encrypt_no="+encrypt_no+"&mem_id="+mem_id;
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", port);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.ssl.trust", host);
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
String un=username;
String pw=password;
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(un, pw);
}
});
session.setDebug(true); //for debug
Message mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("ruthhere@naver.com"));
mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
mimeMessage.setSubject(subject);
mimeMessage.setText((String) message);
mimeMessage.setContent(message, "text/html; charset=utf-8");
Transport.send(mimeMessage); }
System.out.println("an email has been sent");
if(occu_code!=0) return "redirect:/pay_after?occu_code="+occu_code+"&mem_id="+occupation.getMem_id();
return "redirect:/main";
}
答案 0 :(得分:0)
您使用mail-template。这link
答案 1 :(得分:0)
有两种可能的方法:
以下是捕获,无论哪种方式,一些客户端都可以正常工作,但对于一些客户端它不会,即使您设法让您的附件工作,由于安全原因主要电子邮件提供商阻止/剥离附加的CSS文件/内容。我建议避免使用css文件尝试内联样式。
<h2><span style="background-color: #ff0000;">Writing HTML Mail</span></h2>
进一步资源:
干杯。