advertisement

Article:
  Giving the Simple Text Editor 'Legs'
Subject:   Java Cocoa Odysee
Date:   2004-03-02 05:01:31
From:   linus4200
Response to: Java Version - Solution

Hello ,


after days of searching for a solution, I found this cocoa java code which guide me to the idea, that you might help me.


I made a simple e-mail interface with interface builder with
4 fields, (from, to, subject,message), whereby from, to, subject, are NSTextFields and I used the NSTextView to be able to write a text inside. On the other hand I have a java code using javamail to send an email, also very simple and one send button.


Now my question how can I pass the NSTextView TEXT CONTENTS into the java code variable message?


Inside the java code the variable message holds the "email message that you send" but I do not know how to fill said variable with the contents of NSTextView. If you have any
suggestion for me it would be great. In any case thank you
for your help,


thx,


linus


the code I produce:


/* SendMail
e-mail function through JavaMail 1.3 from Sun
*/


import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;


public class SendMail {


public NSTextField from; /* IBOutlet */
public NSTextView message; /* IBOutlet */
public NSTextField subject; /* IBOutlet */
public NSTextField to; /* IBOutlet */


public void send(Object sender) throws Exception { /* IBAction */

boolean debug = false;


// defining email variables
String host = "localhost";
String From = from.stringValue();
String To = to.stringValue();
String Subject = subject.stringValue();

// PROBLEM HOW TO USE NSTextView contents to pass it to message

// Get system properties
Properties props = System.getProperties();

// Setup mail server

props.put ("mail.smtp.host", "localhost");



// get session
Session session = Session.getDefaultInstance(props,null);
session.setDebug(debug);


// Define message
MimeMessage messageX= new MimeMessage(session);
messageX.setFrom(new InternetAddress(From));
messageX.addRecipient(Message.RecipientType.TO, new InternetAddress(To));
messageX.setSubject(Subject);
messageX.setText(MessageY);

// send message

Transport.send(messageX);

}


}