I have a dropwizard REST service and I am trying to implement sending verification email link/code once the user signup.
I have a field in my database in the user table called is_active that denotes whether the user is verified or not.
private String email;
@JsonProperty
private String password;
@JsonProperty
private String name;
@JsonProperty
private String surname;
@JsonProperty
private boolean isActive;
I am trying to figure out whats the right way to send this verification email, I have written a class that sends SMTP emails to the user but I am bit skeptical about whether its correct way of sending email or not?
public class SendEmail
{
public static void main(String [] args){
String to = "customer@gmail.com";
String from = "mycompany@gmail.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("verification email");
message.setText("Hello, this is sample verification email ");
Transport.send(message);
System.out.println("message sent successfully....");
}catch (MessagingException mex) {mex.printStackTrace();}
}
}
Is this how I should be implementing or use some external provider like sendgrid for this?
Your approach is fine. Some things to consider:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.