It looks like in http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html, the administrator sends email to another user(from email setting is default). But I actually have a submit form like this:
它看起来像在http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html中,管理员向另一个用户发送电子邮件(默认情况下来自电子邮件设置)。但我实际上有一个这样的提交表单:
<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>
</form>
I actually want user to enter their email address, subject, and body(to email=my gmail is default).
我实际上希望用户输入他们的电子邮件地址,主题和正文(对于email =我的gmail是默认的)。
How do I make change to sendMail method in http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html?
如何在http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html中对sendMail方法进行更改?
I appreciate if someone could help me.
如果有人能帮助我,我感激不尽。
1 个解决方案
#1
0
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:
更改sendEmail方法定义,以便将参数“to”重命名为“customerEmail”。在processRequest方法中,使用request.getParameter(“email”)获取用户输入的电子邮件,并将其传递给sendEmail方法(而不是“to”)。然后,在sendEmail中,更改:
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);
to
message.setFrom(new InternetAddress(customerEmail));
InternetAddress[] address = {new InternetAddress(YOUR EMAIL ADDRESS)};
message.setRecipients(Message.RecipientType.TO, address);
#1
0
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:
更改sendEmail方法定义,以便将参数“to”重命名为“customerEmail”。在processRequest方法中,使用request.getParameter(“email”)获取用户输入的电子邮件,并将其传递给sendEmail方法(而不是“to”)。然后,在sendEmail中,更改:
message.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
message.setRecipients(Message.RecipientType.TO, address);
to
message.setFrom(new InternetAddress(customerEmail));
InternetAddress[] address = {new InternetAddress(YOUR EMAIL ADDRESS)};
message.setRecipients(Message.RecipientType.TO, address);