中午我试图让我的应用程序通过javamail发送html +图像,我只设法发送html,但与图像我有一些问题.我决定创建一个多部分消息,一切顺利,但后来我使用类加载器从WEB-INF/resources/images检索.png文件我得到一个NullPointerExcetion,我不知道为什么会这样?
这是我的EJB(3.0)的样子.我很欣赏这一个我没有太多经验的ClassLoader类(不太了解它).
@Stateless(name = "ejbs/EmailServiceEJB")
public class EmailServiceEJB implements IEmailServiceEJB {
@Resource(name = "mail/myMailSession")
private Session mailSession;
public void sendAccountActivationLinkToBuyer(String destinationEmail,
String name) {
// Destination of the email
String to = destinationEmail;
String from = "dontreply2thismessage@gmail.com";
try {
Message message = new MimeMessage(mailSession);
// From: is our service
message.setFrom(new InternetAddress(from));
// To: destination given
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Uspijesna registracija");
// How to found at http://www.rgagnon.com/javadetails/java-0321.html
message.setContent(generateActivationLinkTemplate(), "text/html");
Date timeStamp = new Date();
message.setSentDate(timeStamp);
// Prepare a multipart HTML
Multipart …Run Code Online (Sandbox Code Playgroud)