Created
January 18, 2021 14:24
-
-
Save ns-github14/c0b2cb7c4274ebaf37b26b132ed0b0dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Send Email using JSP</title> | |
</head> | |
<body> | |
<form name="emailform" action="Recovery.jsp" method="post"> | |
<h1>Recover Your Password</h1> | |
Email ID: <input type="text" name="email" size=50px placeholder="email" required="required"> | |
<input type="submit" name="Email" value="Send Link" > | |
</form> | |
</body> | |
</html> | |
<% | |
if (request.getParameter("Email") != null) { | |
final String subject = "Recover Your Password"; | |
final String messg = "You message here..."); | |
final String from = "abcd@gmail.com"; | |
final String pass = "your password here...."; | |
String host = "smtp.gmail.com"; | |
Properties props = new Properties(); | |
props.put("mail.smtp.ssl.enable","true"); | |
props.put("mail.smtp.host", host); | |
props.put("mail.transport.protocol", "smtp"); | |
props.put("mail.smtp.auth", "true"); | |
props.put("mail.smtp.starttls.enable", "true"); | |
props.put("mail.user", from); | |
props.put("mail.password", pass); | |
props.put("mail.port", 587); | |
Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() { | |
@Override | |
protected PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication(from, pass); | |
} | |
}); | |
try { | |
MimeMessage message = new MimeMessage(mailSession); | |
message.setFrom(new InternetAddress(from)); | |
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); | |
message.setSubject(subject); | |
message.setText(messg); | |
Transport.send(message); | |
result = "Your mail sent successfully...."; | |
out.println(result); | |
} | |
catch (MessagingException mex) { | |
mex.printStackTrace(); | |
result = "Error: unable to send mail...."; | |
out.println(mex); | |
out.println(result); | |
} | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment