I have created a registration form in JSP with an input field for email address. When user submits the form, then the user must get an auto-reply on his/her email address. How can I achieve this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Your question is not very clear. Let me get the requirement right; you need the code to send an email to the user only on successful registration. correct?
In your servlet(which is invoked on submit action),
Send email method would ideally send the request to an JMS(queue) to send the email to the desired user. Below is a snippet to send an email.
Auto-reply? Sorry, that term makes no sense in this particular context. Auto-reply is more a setting on a mailserver which should automatically send a reply back on incoming emails, for example "Thank you, your email is been received, your email will be answered within 24 hours." or something. You don't need this here.
You just want to programmatically send a mail. The mail should contain a link which should activate the account so that the user will be able to login. You see this indeed often on other websites. Here's how you can go about this:
Setup/prepare a SMTP server. A SMTP server is a mail server. Like as that a HTTP server is a web server. You can use an existing one from your ISP or a public one like Gmail. You can even setup a completely own one. For example with Apache James. Whatever way you choose, you should end up knowing the hostname, portnumber, username and password of the SMTP server.
Create a
Mailer
class which can take at least "from", "to", "subject" and "message" arguments and sends a mail using JavaMail. Connect and login the SMTP server by hostname, portnumber, username and password. Create a mail session and send the mail based on the given arguments. Create a dummy test class with amain()
method which runs and tests theMailer
class. Once you get it to work, proceed with next steps.Create another database table
user_activation
with a PKkey
and FKuser_id
referring the PKid
of anuser
table which you should already have. On the existinguser
table, add a boolean/bit fieldactive
which defaults tofalse
/0
.When user registration and insert in the DB succeeds, get the insert
id
from theuser
table, generate a long and uniquekey
withjava.util.UUID
and insert them inuser_activation
table. Prepare a mail message with an activation link where the uniquekey
is included as URL parameter or path and then send this message using theMailer
class you created.Create a
Servlet
which is mapped on an URL pattern matching the activation key links, e.g./activate/*
and extracts the activation key from the URL. Select the associated user from the database and if any exist, then set itsactive
field totrue
/1
and remove the key fromuser_activation
table.On login, only select the user when
active=true
or1
.What about adding user's email address to Bcc field (Blind Carbon Copy)?