Это то, что я сделал. Я использую HTML и Java в качестве серверной части для отправки почты.
<body>
<h3> Please Enter your Email Address </h3>
<form action="Sendmail" method="post">
<input type="text" class="form-control" placeholder="staff_email" email="staff_email">
<input type="submit" value="Submit">
</form>
</body>
На внутренней стороне я использую службу Gmail.
public class EmailUtility{
public static void sendEmail(String host, String port,
final String senderEmail, String senderName, final String password,
String recipientEmail, String subject, String message) throws AddressException,
MessagingException, UnsupportedEncodingException {
// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
// creates a new session with an authenticator
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(senderEmail, password);
}
};
Session session = Session.getInstance(properties, auth);
//creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(senderEmail));
InternetAddress[] toAddresses = { new InternetAddress(recipientEmail) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(message);
//sends the e-mail
Transport.send(msg);
}
}
Я использую Tomcat Server. Пожалуйста, добавьте следующие строки в Интернете. xml Tomcat Server.
<context-param>
<param-name>email</param-name>
<param-value>abc@gmail.com</param-value>
</context-param>
<context-param>
<param-name>name</param-name>
<param-value><Your Name></param-value>
</context-param>
<context-param>
<param-name>pass</param-name>
<param-value> Your Password Comes Here </param-value>
</context-param>