Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
call a class from birt
Vineet Joshi
Hi friends ,
I am not very much aware of java thing inside birt .Below is the java code which i need to call from inside birt report .
Also this java code needs parameter which is to be sent by birt report like Email id .
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
class SendAttachment{
public void sendMail(String to)// throws MessagingException, AddressException
{
final String user="abc@123.com";
final String password="123456";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "smtp.abc.com");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.ssl.enable", "true");
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,password);
}
});
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Message Aleart");
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setText("success");
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
String filename = "SendAttachment.java";
DataSource source = new FileDataSource(filename);
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart1);
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart );
Transport.send(message);
System.out.println("message sent....");
}catch (MessagingException ex) {ex.printStackTrace();}
}
public static void main(String [] args){
SendAttachment client = new SendAttachment();
String to="123@abc.com";
client.sendMail(to);
}
}
regards
Vineet
Find more posts tagged with
Comments
kclark
Are you doing this in the design editor or are you writing the code in native java. If you're writing it natively then you'll either need to associate the project with your report or you can jar it and put that inside the resource folder.