Hey I have this following code:
try
{
// Connection props
Properties props = new Properties();
props.setProperty("mail.smtp.host", host);
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.smtp.user", usuario);
props.setProperty("mail.smtp.auth", "true");
// Prepare the session
Session session = Session.getDefaultInstance(props);
// Constuct the message
MimeMessage message = new MimeMessage(session);
/*Test*/ message.setHeader("Content-Type", "multipart/mixed");
message.setFrom(new InternetAddress(CorreoOrigen));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(CorreoDestino));
message.setSubject(asunto);
Multipart mp = new MimeMultipart();
BodyPart texto=new MimeBodyPart();
/*Test*/ texto.setHeader("Content-Type", "multipart/mixed");
texto.setContent(mensaje,"text/html");
mp.addBodyPart(texto);
MimeBodyPart ajunto=new MimeBodyPart();
ajunto.setHeader("Content-Type", "multipart/mixed");
ajunto.attachFile(NombreArchivo);
mp.addBodyPart(ajunto);
message.setContent(mp);
// message.setContent(mp, "text/html");
// We send it
Transport t = session.getTransport("smtp");
t.connect(usuario,contraseña);
t.sendMessage(message, message.getAllRecipients());
// Close.
t.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
Everytime I send it, it gets sent to the junk folder in Outlook 2007 and I rather it good directly to inbox. It contains simple text (nothing more, I put HTML in case we want to make it "prettier" in the future) and a attachment which can be a generated PDF or a generated ZIP. Once moved to the inbox, the PDF and the ZIP and be downloaded perfectly and opened and its content can be viewed so there is nothing stange or anything about it.
How can I fix this so it goes directly to the inbox? Thank you.
BTW, /*Test*/ lines did not work.