我想设置我的mime消息的标题顺序。我尝试过实现mimemessage并重写writeTo方法。但是,我无法理解它是如何工作的。我发送了一条示例消息,但最终收到了两次头文件。任何人都可以请帮我清楚这一点。以下是我的消息类。使用javamail设置标题顺序
public class MyMessage extends MimeMessage{
private String subject;
private String encodingtype;
public MyMessage(Session session) {
super(session);
this.session=session;
}
@Override
public void writeTo(OutputStream out) throws java.io.IOException, MessagingException{
try{
String replyto = ("\""+displayname+"\" <"+displayfrom+">");
String fromheader = ("\""+displayname+"\" <"+mailfrom+">");
out.write(("Date: "+new Date()+"\r\n").getBytes("UTF-8"));
out.write(("From: "+fromheader+"\r\n").getBytes("UTF-8"));
out.write(("Reply-To: "+replyto+"\r\n").getBytes("UTF-8"));
out.write(("To: "+getAddress(email)+"\r\n").getBytes("UTF-8"));
out.write(("Content-Type: text/html; charset=\"UTF-8\"\r\n").getBytes("UTF-8"));
out.write(("Content-Transfer-Encoding: "+encodingtype+"\r\n").getBytes("UTF-8"));
out.write("\r\n".getBytes("UTF-8"));
out.write("<html><body><h1>HI</h1></body></html>\r\n".getBytes("UTF-8"));
}catch(Exception e){
System.out.println(e);
}
}
}
在此先感谢。
我试过这两种情况。但是,当我重写上述方法并设置所需的顺序时,标题被视为内容。例如,我已将** To **标头设置为值[email protected]。但是,当我发送电子邮件给javax.mail.SendFailedException:没有收件人地址异常。如果我明确设置收件人地址,我正在收到带有两个** To **标题的电子邮件。请帮我找到我失踪的地方。谢谢回复。 –
我需要看看代码,看看你做错了什么。如果您不想在此发布,请通过[email protected]发送给我。 –
非常感谢。将代码从[email protected]发送到[email protected]。等待您的回复。谢谢。 –