-2

When you visit most websites, they have a column called "contact us" where they let you send a message. Their form looks something 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>
</form>

What I want is this: when user hit submit, I want this message to be directly sent to my gmail (not though Microsoft Outlook). It has something to do with JavaMail API. I am trying to follow how to send an email from jsp/servlet? and http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html. But confused about their send or sendMail methods respectively.

Problem: sender's email setting changes every time.

I appreciate if someone could help me out.

Community
  • 1
  • 1
user3014926
  • 1,061
  • 7
  • 18
  • 26
  • 1
    What are you confused about specifically? What have you tried so far? – Mike B Jan 10 '14 at 22:31
  • You should try to put your confusion into words – keyser Jan 10 '14 at 22:31
  • The email is only sent through "Microsoft Outlook" if your SMTP server is a Microsoft one. – developerwjk Jan 10 '14 at 22:43
  • OK, I am trying to do something like this: http://stackoverflow.com/contact – user3014926 Jan 10 '14 at 22:43
  • OK. the contact page you cited is submitting the form to StackOverflow's webserver -- you can see the details if you View Source on the page -- and the server is then deciding what to do with it (which may be mail, or more likely adding it to a database which their customer service folks access). So I presume that what you want is indeed a server-side implementation. Sender's email address would have to be specified by the user as part of the form, if you want it. It'd flow through whatever outgoing mail server you choose, using whatever authentication you normally supply to it. Right? – keshlam Jan 10 '14 at 22:52
  • Correct, that's what I want. – user3014926 Jan 10 '14 at 22:54
  • Do I need to know the setting for user's email? – user3014926 Jan 10 '14 at 23:18
  • http://stackoverflow.com/questions/3757442/how-to-send-an-email-from-jsp-servlet --- The send(from, to, subject, message) method looks different from sendMail method in http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html. – user3014926 Jan 11 '14 at 05:29
  • It looks like in http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/javamail/javamail.html, the administrator sends email to another user. I want user to send an email to administrator (my gmail). – user3014926 Jan 11 '14 at 05:36
  • "Problem: sender's email setting changes every time." Do you understand what a variable is? A variable is what you use when you are programming a computer, for something that "changes every time". And if you don't even understand that, it's too early for you to use StackOverflow, you should learn some basic programming skills first. – Robin Green Jan 11 '14 at 10:44

2 Answers2

2

The easiest way to do this would be to set up an html mailto form, which will do all the work in the user's browser rather than needing any java or server involvement at all. Websearch on that phrase will find more information.

The biggest advantage of the more complicated solutions is that they hide the address being mailed to, to some degree, which can help reduce how badly you're targeted by spammers.

keshlam
  • 7,931
  • 2
  • 19
  • 33
  • I know how to setup mailto form in html, but this is not user friendly since user has to loggin to their mail browser and send them. It's no big difference from http://www.w3schools.com/html/tryit.asp?filename=tryhtml_mailto. – user3014926 Jan 10 '14 at 22:42
0

You seem to be under the impression that it somehow logs in to the user's own mail server and sends it, or something. Obviously, if you think about this for 5 seconds, this cannot be the case, because it doesn't ask for a username and password so it wouldn't be able to log in, some user's mail servers are behind a firewall for outbound purposes... there are all sorts of reasons why that couldn't possibly work.

So what it actually must do, more or less, is use the same mail server each time. Its own mail server, or a corporate mail server owned by the receiver.

Robin Green
  • 32,079
  • 16
  • 104
  • 187