如何使用JSP在电子邮件中插入链接

时间:2018-04-25 21:02:58

标签: java jsp javamail

我想在JSP中插入一个带电子邮件的链接。我在电子邮件中成功收到HTML消息,但链接未显示...我正在使用Java邮件...我的代码是这样的:

public void sendConfirmationMail() throws MalformedURLException, IOException{
    try {
        Properties properties = System.getProperties();
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.socketFactory.port", "465");
        properties.put("mail.smtp.ssl.enable", "true");
        properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");    
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.port", "465");                        
        Session mailSession = Session.getInstance(properties,
                new javax.mail.Authenticator() {
                    @Override
                    protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(fromEmail,password);
        }
        });
        mailSession.setDebug(true);
        MimeMessage mail = new MimeMessage(mailSession);      
        mail.setFrom(new InternetAddress(fromEmail));
        mail.setRecipients(Message.RecipientType.TO,InternetAddress.parse(toEmail));
        MimeBodyPart cuerpo = new MimeBodyPart();
        cuerpo.setText(message,"UTF-8","html");
        Multipart part = new MimeMultipart();
        part.addBodyPart(cuerpo);
        mail.setContent(part);
        mail.setSubject(subject);
        Transport.send(mail);
    } catch (MessagingException ex) {
        Logger.getLogger(MailController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

我怎样才能做到这一点?

0 个答案:

没有答案