我正在尝试发送一封带有 RTF 字符串表的电子邮件,但是当我检查电子邮件的消息正文时,该表丢失了格式,所以我想知道我做错了什么,这是以下 block 要发送的代码和电子邮件
public static void send(String asunto, String texto, String emailDestinatario){
final String username = "myemail@gmail.com";
final String password = "mypass";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse( emailDestinatario));
message.setSubject(asunto);
message.setText(texto);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
我需要发送哪些其他配置并通过电子邮件发送并识别我的表格格式?
这是一个文档example通过电子邮件发送
我得到类似的东西(表格丢失了格式)
TARIFAS EMPLEADOS
TARIFA
IVA
TOTAL
EMPLEADOS HASTA $150.000.000
94,000
15,040
109,040
EMPLEADOS MAYOR DE $150.000.000
160,000
25,600
185,600
最佳答案
您是否尝试过类似的操作:
MimeMessage message = new MimeMessage(sesion);
.
.
.
//Config your message....
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent("RTF HTML TEXT", "text/html");
mp.addBodyPart(htmlPart);
message.setContent(mp);
Transport.send(message);
关于java - 在 RTF 消息 JavaMail 中发送表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30539286/