In my application, I want to send an html template to users email address. Everithing works correctly when I programmatically create html, but now I want it to read the html text from a file in my application and send it. I get a FileNotFoundException and I don't know how to find this .txt file. See code:
public void sendAccountActivationLinkToBuyer(String destinationEmail,
String name) {
String to = destinationEmail;
String from = "myEmail@gmail.com";
try {
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject("Registration succeded");
message.setText(generateActivationLinkTemplate());
Date timeStamp = new Date();
message.setSentDate(timeStamp);
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
private String generateActivationLinkTemplate() {
String htmlText = "";
try {
File f = new File("");
BufferedReader br = new BufferedReader(new InputStreamReader(f.getClass().getResourceAsStream("./web/emailActivationTemplate.txt")));
String content = "";
String line = null;
while ((line = br.readLine()) != null) {
content += line;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return htmlText;
}
The second method gives me problems, I can not find this .txt file. What should I do? I created a folder in the WebContent folder, now the web folder is next to META-INF and WEB-INF (I think this is a good place to store my images, templates, css ...) Inside the folder I manually inserted emailActivationTemplate.txt Now I need to read it. Any ideas?
This is the console output:
SEVERE: java.io.FileNotFoundException:.\web\emailActivationTemplate.txt( )