• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

java mail attachment notification

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jayesh Pokar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic