H, I am sending mail with attachment but the problem i am facing is.....I want to show user that "Now it is attaching"....."Now it is sending mail"...such notification.
I am using Transport .send(msg), what it does is it attach the attachment first and then send mail, So I cant able to distinguish what is going on in background.
I use session.debug(true) , it notifies all things to me in console but what i want is some trigger or callback which says now attaching, now sending like that....
Here is my code..
public void send1() {
Properties props = new Properties();
props.put("mail.smtp.host", email.getSmtpServer());
props.put("mail.smtp.port", email.getSmtpPort());
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(true);
emailMessage = new MimeMessage(session);
emailMessage.setSubject(email.getEmailSubject());
if(email.getAttachedFile().toString().trim().equals("")){
emailMessage.setText(email.getEmailBody());
}else{
attachFile(email.getAttachedFile());
}
emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(email.getEmailTo(),"XYZ"));
Transport transport=session.getTransport("smtp");
transport.addConnectionListener(new EmailTransportListener(callBackObject));
transport.addTransportListener(new EmailTransportListener(callBackObject));
transport.connect();
InternetAddress[] a=new InternetAddress[1];
a[0]=new InternetAddress("
[email protected]");
transport.sendMessage(emailMessage,a);
} catch (Exception mex) {
mex.printStackTrace();
}
}
Thanks.