Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Have an app email some text

Have an app email some text
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Nov 29, 2001, 12:39 AM
 
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
Reply With Quote
Nov 30, 2001, 12:12 PM
 
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
Reply With Quote
Nov 30, 2001, 01:43 PM
 
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
Reply With Quote
Dec 1, 2001, 09:03 AM
 
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
Reply With Quote
Dec 1, 2001, 06:33 PM
 
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 &lt;your smtp server&gt; 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
Reply With Quote
Dec 1, 2001, 08:33 PM
 
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
Reply With Quote
Dec 2, 2001, 08:37 AM
 
I think you want to use Mail's services,

See here: http://developer.apple.com/techpubs/...s/Services.pdf
     
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status: Offline
Reply With Quote
Dec 3, 2001, 02:01 PM
 
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
Reply With Quote
Dec 3, 2001, 10:47 PM
 
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
Reply With Quote
Dec 8, 2001, 07:43 AM
 
http://www.cocoadev.com/index.pl?SendingEmail

maybe what you are looking for.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Dec 8, 2001, 09:49 AM
 
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?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2