This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

java mail attachment notification  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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("abc@gmail.com");
transport.sendMessage(emailMessage,a);

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

Thanks.
 
Jayesh Pokar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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;
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!