How do I send HTML email in Spring MVC?

后端 未结 6 913
[愿得一人]
[愿得一人] 2020-12-01 07:21

I have successfully sent simple email using this:

SimpleMailMessage mailMessage = new SimpleMailMessage();

mailMessage.setTo(\"someone@abc.com\");
mailMessa         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-01 07:51

    Class Level:

    public String sendEmailToUsers(String emailId,String subject, String name){
        String result =null;
        MimeMessage message =mailSender.createMimeMessage();
        try {
    
            MimeMessageHelper helper = new MimeMessageHelper(message, false, "utf-8");
            String htmlMsg = ""
                        +"Your onetime password for registration is  " 
                            + "Please use this OTP to complete your new user registration."+
                              "OTP is confidential, do not share this  with anyone.";
            message.setContent(htmlMsg, "text/html");
            helper.setTo(emailId);
            helper.setSubject(subject);
            result="success";
            mailSender.send(message);
        } catch (MessagingException e) {
            throw new MailParseException(e);
        }finally {
            if(result !="success"){
                result="fail";
            }
        }
    
        return result;
    
    }
    

    XML Level:

        
        
        
        
        
        
            
                smtp
                true
                true
            
        
    
    

提交回复
热议问题