aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes java mail attachment notification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "java mail attachment notification" Watch "java mail attachment notification" New topic
Author

java mail attachment notification

Jayesh Pokar
Greenhorn

Joined: Apr 26, 2011
Posts: 10
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("abc@gmail.com");
transport.sendMessage(emailMessage,a);

} catch (Exception mex) {
mex.printStackTrace();
}
}

Thanks.
Jayesh Pokar
Greenhorn

Joined: Apr 26, 2011
Posts: 10
Here I am writing my attachment code.....

private int attachFile(File file){
try {

// Create the message part
BodyPart messageBodyPart = new MimeBodyPart();

// Fill the message

messageBodyPart.setText(email.getEmailBody());

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

// Part two is attachment
messageBodyPart = new MimeBodyPart();

DataSource source = new FileDataSource(file);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName("greetings");
multipart.addBodyPart(messageBodyPart);

// Put parts in message
emailMessage.setContent(multipart);

} catch (MessagingException e) {

}
return 1;
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java mail attachment notification
 
Similar Threads
please help!urgent...on javamail API.
please help on java mail API.
sending mail with JavaMail
Auto Generated Email using Java
problem sending mail to other domains