I need to use sendmail in bash to send my e-mail in Java. I cant use javamail due to configuration duplication…
package fr.thales.edf.reportEmailAcrAcq.email;
import java.io.IOException;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class SendHTMLEmail {
private static final String SENDMAIL = "sendmail -R hdrs -N never -t -v < ";
private static final Logger LOGGER = Logger.getLogger(SendHTMLEmail.class
.getName());
private String fileName;
public SendHTMLEmail(String fileName) {
this.fileName = fileName;
}
public void sendMail() {
String command = SENDMAIL + fileName;
try {
Runtime r = Runtime.getRuntime();
LOGGER.log(Level.INFO, "Envoi de la commande: " + command);
Process p = r.exec(command);
p.waitFor();
LOGGER.log(Level.INFO,
"Résultat de l'envoi de l'e-mail : " + p.getOutputStream());
} catch (InterruptedException ex) {
LOGGER.log(Level.FATAL, ex.getMessage());
} catch (IOException ex) {
LOGGER.log(Level.FATAL, ex.getMessage());
}
}
}
This is my log file:
INFO - Command: sendmail -R hdrs -N never -t -v < ACR_20130111_100744.html
But my program never send e-mail and sendmail command still running (even after 2 hours).
Another thing, when i use the same command in a bash script, it works in 5 minutes…
I found the solution:
I found the answer on this forum :
http://www.coderanch.com/t/379834/java/java/executing-shell-script-java