这是一个小邮件脚本,它从表单中获取信息,然后发送邮件。它就像一个魅力,只有一个问题是发件人地址和主题不起作用。邮件没有发件人地址,也没有主题。
有谁知道怎么回事?
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, Exception {
response.setContentType("text/html;charset=UTF-8");
//PrintWriter out = response.getWriter();
//SMTPserver en de mail naar waar de mensen hun mail versturen
String smtpServ = "uit.telenet.be";
String to = "ddd@gmail.com";
String from = request.getParameter("mail");
String subject = request.getParameter("subject") + "geschreven door: " + request.getParameter("naam");
String emailContent = request.getParameter("beschrijving");
response.setContentType("text/html");
try {
sendMessage(smtpServ, to, from, subject, emailContent);
} catch (Exception e) {
throw new ServletException(e.getMessage());
}
}
private void sendMessage(String smtpServer, String to, String from,
String subject, String emailContent) throws Exception {
try{
SmtpClient client = new SmtpClient(smtpServer);
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("Naar: " + to);
message.println("Onderwerp:" + subject);
message.println(emailContent);
message.println();
message.println("Het Burgerdemocratie Team");
message.println();
message.println();
client.closeServer();
}
catch (IOException e){
System.out.println("ERROR tijdens het verzenden van de mail:"+e);
}
}