如何解决这个问题;未使用java在outlook中显示邮件正文;?
这是我发送邮件的java代码,但当我使用此代码发送邮件时,除了正文文本之外,所有内容都被发送 outlook中未显示此正文文本,这是我的代码 包装样品如何解决这个问题;未使用java在outlook中显示邮件正文;?,java,jakarta-mail,Java,Jakarta Mail,这是我发送邮件的java代码,但当我使用此代码发送邮件时,除了正文文本之外,所有内容都被发送 outlook中未显示此正文文本,这是我的代码 包装样品 import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.Message.RecipientType; import javax.mail.MessagingException; import
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendMail {
public void sendMail(String m_from,String m_to,String m_subject,String m_body){
try {
Session m_Session;
Message m_simpleMessage;
InternetAddress m_fromAddress;
InternetAddress m_toAddress;
Properties m_properties;
m_properties = new Properties();
m_properties.put("mail.smtp.host", "fffffff");
m_properties.put("mail.smtp.auth", "true");
m_properties.put("mail.smtp.starttls.enable", "true");
m_properties.put("mail.smtp.port", "587");
m_Session=Session.getDefaultInstance(m_properties,new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("anthony.savarimut","1wr345d@1"); // username and the password
}
});
m_Session.setDebug(true);
m_simpleMessage = new MimeMessage(m_Session);
m_fromAddress = new InternetAddress(m_from);
m_toAddress = new InternetAddress(m_to);
m_simpleMessage.setFrom(m_fromAddress);
m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
m_simpleMessage.setSubject(m_subject);
m_simpleMessage.setContent(m_body, "text/html; charset=utf-8");
//m_simpleMessage.setContent(m_body,"text/plain");
Transport.send(m_simpleMessage);
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SendMail send_mail = new SendMail();
String empName = "Antony Raj S";
String title ="<b>Hi !"+empName+"</b>";
StringBuffer mailBody = new StringBuffer();
mailBody.append("<b><Hi "+empName+">");
mailBody.append("<br>");
mailBody.append("<Please Apply Leave for the following date(s )"+empName+">");
mailBody.append("<br>");
mailBody.append("<Regards>");
mailBody.append("<br>");
mailBody.append("<HR Team>");
mailBody.append("<br>");
mailBody.append("<Slingmedia>");
send_mail.sendMail("anthony.savarimut@xxxxxx.com", "anthony.savarimut@yyyyy.com", "Please apply for leave for the following dates", mailBody.toString());
}
}
import java.util.Properties;
导入javax.mail.Authenticator;
导入javax.mail.Message;
导入javax.mail.Message.RecipientType;
导入javax.mail.MessaginException;
导入javax.mail.PasswordAuthentication;
导入javax.mail.Session;
导入javax.mail.Transport;
导入javax.mail.internet.InternetAddress;
导入javax.mail.internet.mimessage;
公共类SendMail{
public void sendMail(字符串m_from、字符串m_to、字符串m_subject、字符串m_body){
试一试{
会议m_会议;
消息m_simpleMessage;
互联网地址m_fromAddress;
互联网地址m_toAddress;
属性m_属性;
m_属性=新属性();
m_properties.put(“mail.smtp.host”,“fffffffff”);
m_properties.put(“mail.smtp.auth”、“true”);
m_properties.put(“mail.smtp.starttls.enable”、“true”);
m_properties.put(“mail.smtp.port”,“587”);
m_Session=Session.getDefaultInstance(m_属性,新验证器(){
受保护的密码身份验证getPasswordAuthentication(){
返回新密码身份验证(“anthony.savarimut”1wr345d@1“”;//用户名和密码
}
});
m_Session.setDebug(true);
m_simpleMessage=新MIMMessage(m_会话);
m_fromAddress=新的Internet地址(m_from);
m_toAddress=新的Internet地址(m_to);
m_simpleMessage.setFrom(m_fromAddress);
m_simpleMessage.setRecipient(RecipientType.TO,m_toAddress);
m_simpleMessage.setSubject(m_subject);
setContent(m_body,“text/html;charset=utf-8”);
//m_simpleMessage.setContent(m_body,“text/plain”);
传输。发送(m_simpleMessage);
}捕获(消息例外){
例如printStackTrace();
}
}
公共静态void main(字符串[]args){
SendMail send_mail=new SendMail();
字符串empName=“Antony Raj S”;
字符串title=“嗨!”+empName+”;
StringBuffer邮件体=新的StringBuffer();
邮件正文。附加(“”);
mailBody.append(“
”);
邮件正文。附加(“”);
mailBody.append(“
”);
邮件正文。附加(“”);
mailBody.append(“
”);
mailBody.append(“
”);
mailBody.append(“
”);
邮件正文。附加(“”);
send_mail.sendMail(“安东尼。savarimut@xxxxxx.com安东尼。savarimut@yyyyy.com“,“请在以下日期申请休假”,mailBody.toString());
}
}
请帮我解决这个问题
问候
托尼试着把身体摆成这样:
MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
messageBodyPart.setContent(bodytext, type.type);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
您不需要使用多部分内容,原始代码应该可以工作。您可以尝试用mimessage.setText()替换setContent方法,但这也不会有什么不同。您可能还想阅读此JavaMail常见问题解答条目,这可能会有所不同: