When we call the below java source from pl/sql an empty body is being sent to the recipient, whereas if i copy this code and run in stand alone jdk the recipient is able to see the body. Any help would be greatly appreciated.
But I need to make this work with addbodypart and multipart as i'm planning to embed images later in the mail.
create or replace and compile java source named MailExMulti as
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
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.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.sql.Clob;
public class SendSimpleMail {
public static void sendmail(String s) {
Properties props = new Properties();
props.put("mail.smtp.host", "xxx.xxx.com");
props.put("mail.smtp.socketFactory.port", "123");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "123");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("aaa@oracle.com", "aaa");
}
});
try {
MimeMessage msg = new MimeMessage(session);
javax.mail.Multipart multiPart = new MimeMultipart("mixed");
MimeBodyPart textpart = new MimeBodyPart();
textpart.setText("\r\nasdsadsadsad");
multiPart.addBodyPart(textpart);
msg.setFrom(new InternetAddress("aaaa@oracle.com"));
msg.setRecipients(Message.RecipientType.TO, "aaaa@oracle.com");
msg.setSubject("Simple Test Mail");
msg.setSentDate(new Date());
msg.setContent(multiPart);
msg.saveChanges();
File file;
file = new File("D:"+"//msg1.txt");
try{
msg.writeTo(new FileOutputStream(file));
}
catch(Exception e)
{
System.out.println("File does not exists...");
}
Transport.send(msg);
System.out.println("---Done---");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}