I have the following email:
Subject = Hello!
Body = Bla bla bla bla.
Recipients = "carlos@mail.com", "mike@mail.com"
Now I want to parse that fields following RFC822, but I can't find it.
What I need?
All fields(Subject,Body,Recipients) -> Formatter(java and/or objective-c) -> String according RC822
What I tried?
The problem is they are session oriented and I don't have credentials or host.
Update
I need something like this but instead using message.writeTo(...)
I want something like String dataRFC822 = message.getRFC822String();
// Recipient's email ID needs to be mentioned.
String to = "destinationemail@gmail.com";
// Sender's email ID needs to be mentioned
String from = "fromemail@gmail.com";
// Get the Session object. Which I have not and I don't want it.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
// Create a default MimeMessage object.
Message message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
// Set Subject: header field
message.setSubject("Testing Subject");
// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
// Now set the actual message
messageBodyPart.setText("This is message body");
// Create a multipar message
Multipart multipart = new MimeMultipart();
// Set text message part
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
String filename = "/home/manisha/file.txt";
DataSource source = new FileDataSource(filename);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
// Send the complete message parts
message.setContent(multipart);
//instead write it on a stream i I want get back the string formated according to rfc822
message.writeTo(...);
} catch (MessagingException e) {
throw new RuntimeException(e);
}