is it possible not to include the account password for the user that will send the email. i tried not to put password but it does not work. the email that can send only is the one that is set. please help. this is the code:
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%
String host="", user="", pass="";
host = "smtp.gmail.com"; //"smtp.gmail.com";
user = "email"; // email id to send the emails
pass = "password"; //Your gmail password
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
String to = request.getParameter("to");// out going email id
String from = user;// Email id of the sender/server
String subject = "subject";
String messageText = request.getParameter("body");
boolean sessionDebug = true;
Properties props = System.getProperties();
props.put("mail.host", host);
props.put("mail.transport.protocol.", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
Session mailSession = Session.getDefaultInstance(props, null);
out.println("mailSession : " + mailSession);
mailSession.setDebug(sessionDebug);
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setContent(messageText, "text/html"); // use setText if you want to send text
Transport transport = mailSession.getTransport("smtp");
transport.connect(host, user, pass);
try
{
transport.sendMessage(msg, msg.getAllRecipients());
out.println("Email sent");
}
catch (Exception err)
{
err.printStackTrace();
}
transport.close();
%>