my problem is that in below code as long as to
has the @
in it there is no error! For example if I enter x@y
there is no error! How can I show an error when the email address doesn't exists or domain name is incorrect?
public void sendMail(String content, String to, String subject) {
MimeMessage message = mailSender.createMimeMessage();
try{
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(simpleMailMessage.getFrom());
helper.setTo(to.split(","));
helper.setSubject(subject);
helper.setText(String.format(simpleMailMessage.getText(), content));
}catch (MessagingException e) {
e.printStackTrace();
}
mailSender.send(message);
System.out.rpint("email was sent to "+to+" successfully");
}