Organizational Research By

Surprising Reserch Topic

how do i send an email using javamail

how do i send an email using javamail  using -'jsp,servlets,javamail'

It looks like in, the administrator sends email to another user(from email setting is default). But I actually have a submit form like this:

<form action="contact" method="post">
<p>Your email address: <input name="email"></p>
<p>Mail subject: <input name="subject"></p>
<p>Mail message: <textarea name="message"></textarea></p>
<p><input type="submit"><span class="message">${message}</span></p>

I actually want user to enter their email address, subject, and body(to email=my gmail is default).

How do I make change to sendMail method in

I appreciate if someone could help me.

asked Oct 19, 2015 by deven.bendale
0 votes

Related Hot Questions

1 Answer

0 votes

Change the sendEmail method definition so the parameter "to" is renamed to "customerEmail". In the processRequest method, get the email the user entered using request.getParameter("email"), and pass that to the sendEmail method (instead of "to"). Then, in sendEmail, change this:

message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);


message.setFrom(new InternetAddress(customerEmail));
InternetAddress[] address = {new InternetAddress(YOUR EMAIL ADDRESS)};
message.setRecipients(Message.RecipientType.TO, address);
answered Oct 19, 2015 by ankitarajoria4