1

I have written a code in order to be able to launch the default email service provider which is outlook for me. this is the code i have:

if(role.getValue().equals("1")) {

 Desktop desktop = Desktop.getDesktop();
    String message = "mailto:username@domain.com?subject=New_Profile&body=NewProfile";

    try {
            desktop.mail(uri);
    } catch (IOException e) {
    // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

I am trying to attach something to the email automatically but its not working. Instead, will it be possibly to retrieve some data from input fields in my program and automatically add that data as body to the email?

I tried embedding a statement somehow, but its not working. could someone please advise?

Desktop desktop = Desktop.getDesktop();
String message = "mailto:username@domain.com?subject=New_Profile&body=person.getPdfName()";

Why would the code above not do anything? Is person.getPdfName() misplaced?

Radu Murzea
  • 10,724
  • 10
  • 47
  • 69

2 Answers2

0

Have a look at these answers, not sure any of them solve your problem, but they do give a decent description of why its not that simple. Not all email clients support attachments in this way.

Start Mail-Client with Attachment?

How to open an email client and automatically attach file in java

http://forums.devshed.com/windows-help-34/defaut-mail-client-with-attachment-on-xp-71305.html

Community
  • 1
  • 1
Blueberry
  • 2,211
  • 3
  • 19
  • 33
0

Java has an API that is able to send messages and perform all the necessary functions, such as attach files. Check the class MimeMessage to help you.

In your case, I believe that the body of your message would become a simple text containing the name of the PDF, isn't that so?

rlinden
  • 2,053
  • 1
  • 12
  • 13
  • well basically, i have already created a pdf export button, where all the data from the input fields is extracted to a pdf file. now what i need to do is to be able to send an email with all the data. so literally, if i could gather together all data and email it across that would be fine. so i wouldnt necessarily need an attachment. –  Jul 11 '12 at 14:07