 |
 |
Have an app email some text
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
I am working on an app in which I would like to create a command for emailing some text. I got some help in here for getting a button to pop open a web browser and go to a URL. Now, I need a button/command to get the users default email client to open up and put some text in a message body. I have been using the Cocoa Java API's.
The text I want to be inserted into a email body is currently in an NSTextView.
Any help is always help to me javascript: x()
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
I haven't tried this my self, but have you tried passing it a "mailto:" URL? Theoretically, the URL handler should open a browser for "http://" URL's, and the standard email client for "mailto:" URL's.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2000
Location: San Francisco, CA
Status:
Offline
|
|
Originally posted by macrophyllum:
<STRONG>I am working on an app in which I would like to create a command for emailing some text. I got some help in here for getting a button to pop open a web browser and go to a URL. Now, I need a button/command to get the users default email client to open up and put some text in a message body. I have been using the Cocoa Java API's.
The text I want to be inserted into a email body is currently in an NSTextView.
Any help is always help to me javascript: x()</STRONG>
There are a few Java libraries available which implement mail sending with SMTP. It would be a good excercise to extend them to utilize Mac specific settings for the essentials (like the current users e-mail, STMP server, etc. from the Internel control panel). I actually utilized one to write a simple e-mail sender in Java Cocoa (but required that hte SMTP server be entered by the user).
Just do a well worded search on Google, you should find the library downloads.
Michael
|
|
--
Michael F. Kamprath
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
I think putting the mailto: into URL would work, but I haven't tried it. But it still doesn't get me over the problem of inserting text into the body of the email.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
Well, it depends on exactly where and what you're trying to send. But, for an example, if you're trying to get a user to automatically send you email, it's relatively simple.
Simply make a connection to your SMTP server, then send something like:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
HELO your_domain.com
MAIL FROM: user@their_domain.com
RCPT TO: you@your_domain.com
DATA
Subject: test message from user
Message body, blah blah blah.
.
</font>[/code]
Read RFC821 for more information on the SMTP protocol. You can try the above example from the terminal app. Make a connection to your SMTP server by typing in "telnet <your smtp server> 25" then copy and paste the above code in there (with the appropriate addresses and domains).
If you're trying to let your user email some other user's email address, it could be a little bit more involved. You would have to get the MX record for the domain (it's often different to what's used in the email address) to get the SMTP server, or you can try and relay through the user's SMTP server, but you might have to authenticate with POP first if the user's SMTP server has "POP before SMTP" (which is basically the standard practice now).
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
What I would to do is this: I have a window that has a NSTextView in it. The user can enter text into the text view. I want it so that the user can click a button and it opens their default email program creates a new email with no address and no subject, but puts the strings from then NSTextView into the body of the email.
Gotta any more suggestions?
Thanks for the help so far...
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
Mail's services sounds good, but it won't work with any other email client...
I was wondering, if you could pass text with a mailto: URL. I'm sure I've seen them with the address and subjects specified, so you might be able to pass the message body in the URL too (something like "mailto:email@domain.com?body=messagebody"). I can't remember the exact syntax for this, and I'm not sure if the URL handler supports this...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
OK, so using the mailto: URL works good except for one problem. I can't seem to combine strings and then pass that into my URL and have it work correctly. this is what I got so far:
//BEGIN EXAMPLE CODE
java.net.URL myURL = null;
String aString = myAppsTextVew.string();
String email = "mailto:?subject=WhyWontThisWork&body=";
String all = email+aString;
try {
myURL = new java.net.URL(all);
} catch (java.net.MalformedURLException e) {
}
NSWorkspace.sharedWorkspace().openURL(myURL);
//END EXAMPLE CODE
I get a "LSOpenCFURLRef() returned -50 for URL (null)" error. If I use a System.out.println(all), the String all, has everything I want in it.
Got any suggestions folks?
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Thanks for the URL. That looks like it might work. Now, can I just add the Message.frameworks and then the classes will be available in Java? Or will it only work in Obj-C?
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|