Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-19-2009, 12:35 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default Include URL in email

When sending an email from your app (i.e. user click a button and mail launches) how do you include a URL in the body of the email?
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-19-2009, 12:41 PM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Same way you include any other text as the body.

mailto:[someone@somewhere.com]?[subject=Escaped%20Text&]body=More%20escaped%20text

The trick is properly escaping the text. All spaces, question marks, ampersands, etc. must be escaped in the embedded URL so it's not confused as part of the mailto URL.

There is a method on NSString that makes this trivial. I'm deliberately going to make you search the docs for it
RickMaddy is offline   Reply With Quote
Old 01-19-2009, 12:52 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

haha thanks RickMaddy I'll have a look now.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-20-2009, 01:04 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

ok so I've had a look at the docs and still can't get this to work right. Here is the code I call when the email button is tapped:

Code:
-(void)emailClicked{
	
	NSString *body = @"This is a test %20http://www.google.com%20";
	NSString *utfEncoded = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
	NSString *urlString = [NSString stringWithFormat:@"mailto:?subject=test&body=%@", utfEncoded];
	NSURL *url = [[NSURL alloc] initWithString:urlString];
	[[UIApplication sharedApplication] openURL:url];


}
The link in the body just shows up with %20 around it. I thought the %20 showed that is was a link. I must be wrong. What mistakes am I making?
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-20-2009, 01:08 PM   #5 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

First off, there is no need to manually put the %20 in the original body string. %20 is what space characters get replaced with. 20 is the hex value for the ASCII value of a space character.

Add an NSLog statement and print out utfEncoded and post that result here.

What do you see in the email after Mail.app is launched?
RickMaddy is offline   Reply With Quote
Old 01-20-2009, 01:15 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

I think it might actually be working. Is it supposed to make the link a hyperlink? Should I be able to click where it says Google and go to google or should it just say the link.

Currently the body says everything it is supposed to but the google link does not open google.
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-20-2009, 01:22 PM   #7 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Whether a URL appears as a link or not is up to the mail application. In one of my apps I generate an email and send it via the Mail.app. Links do appear in the body of the email as expected but my email body is in HTML and the links are using standard <a href="">text</a> type markup.

I did notice that a URL in my signature does not appear as a link. So my guess is that a URL does not normally appear as a link when composing a text email. And this is fine for what you are doing. Most likely the receiver of the email will see the URL as a link when the receive the email.
RickMaddy is offline   Reply With Quote
Old 01-20-2009, 01:23 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

Thanks RickMaddy I understand better now. Thanks for your help
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-20-2009, 01:45 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Ireland
Age: 21
Posts: 472
kieran12 is on a distinguished road
Default

Last question on this post. I promise. If I want to format my email in HTML where do I place it in the code? Is it after the body=

Here is my code:

Code:
@"mailto:email@email.com?subject=Hello&body="
Thankyou
__________________
On the iOS App Store
kieran12 is offline   Reply With Quote
Old 01-20-2009, 02:29 PM   #10 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

It's the same as a text email except the body is HTML markup instead of plain text.
RickMaddy is offline   Reply With Quote
Old 04-01-2009, 01:51 PM   #11 (permalink)
Registered Member
 
tawpie's Avatar
 
Join Date: Jul 2008
Posts: 347
tawpie is an unknown quantity at this point
Default

Quote:
Originally Posted by RickMaddy View Post
It's the same as a text email except the body is HTML markup instead of plain text.
Rick... "body is HTML" sounds easy but I get nothing after it hits the <a href="">text</a> tag. Everything that follows that tag is lost, but the email is accepted by mail.app so formatting is not completely out in left field.

Here's the string sent to mail.app
Code:
mailto:?&subject=Test&body=%3CContent-Type:%20Text/HTML%3E%3C?xml%20version=%221.0%22%20encoding=%22UTF-8%22?%3E%3C%21DOCTYPE%20html%20PUBLIC%20%22-//W3C//DTD%20XHTML%201.0%20Transitional//EN%22%20%22http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22%3E%3Chtml%20xmlns=%22http://www.w3.org/1999/xhtml%22%20xml:lang=%22en%22%3E%%3Cbody%3EtextForTesting%0A%3Ca%20href=%22http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294438793&amp;amp;mt=8%22%20title=%22testTitle%22%3Etesting%3C/a%3E%0AtrailingTextToSeeWhatHappens%29%3C/body%3E%3C/html%3E
in a more readable format ("readable" and HTML might not be compatible!) The string prior to encoding looks like: (carriage returns added to assist readability and there is no To: filled in, that's an exercise for the user)
Code:
@"mailto:?&subject=Test&body=
<Content-Type: Text/HTML>
<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\"><body><body>
textForTesting<a href=\"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=123456789&amp;amp;mt=8\" title=\"testTitle\">testing</a>\ntrailingTextToSeeWhatHappens
</body>
</html>"
The resulting email indicates that it is still "Text/plain", so I'm wondering if you might share how you tell mail that it needs to deal with the incoming data as HTML?

Pretty please? With sugar on top?

Thanks
__________________
"Hardware will break. Software comes broken" Unknown
Calc-12E <-- ditch your old calculator.
CPR•Choking <-- Review your training, just in case. (Free)
All of Nature NW <-- scrolls in x and y, with pinch zoom AND scrollable text to boot. It can be done ('taint easy tho)
tawpie is offline   Reply With Quote
Old 04-03-2009, 12:51 AM   #12 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Pretty please? With sugar on top?

Thanks
Code:
NSString *body = @"<html>Hey!I wanted to send you this link to check out: <a href='http://www.google.com'>google</a></html>";
		NSString *utfEncoded = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
		NSString *urlString = [NSString stringWithFormat:@"mailto:?subject=test&body=%@", utfEncoded];
		NSURL *url = [[NSURL alloc] initWithString:urlString];
		[[UIApplication sharedApplication] openURL:url];
__________________
Haters gonna Hate
Likers gonna Like

Last edited by Bertrand21; 04-03-2009 at 01:35 AM.
Bertrand21 is offline   Reply With Quote
Old 04-18-2009, 11:34 AM   #13 (permalink)
Registered Member
 
tawpie's Avatar
 
Join Date: Jul 2008
Posts: 347
tawpie is an unknown quantity at this point
Default

B21... thank you!

Things work well until I include the '?' in the app store URL, and that seems to signal mail that "something else important" follows so I'll have to figure that part out but I do definitely appreciate you sharing your code.

Later!
__________________
"Hardware will break. Software comes broken" Unknown
Calc-12E <-- ditch your old calculator.
CPR•Choking <-- Review your training, just in case. (Free)
All of Nature NW <-- scrolls in x and y, with pinch zoom AND scrollable text to boot. It can be done ('taint easy tho)
tawpie is offline   Reply With Quote
Old 08-18-2009, 03:02 AM   #14 (permalink)
iPhone Developer, PlayDom
 
AmanApps's Avatar
 
Join Date: Jul 2009
Posts: 61
AmanApps is on a distinguished road
Default

hello tawpie, any solve to include app store url? I also need that very much!!!
AmanApps is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting 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



» Advertisements
» Online Users: 393
13 members and 380 guests
7twenty7, AppsBlogger, Creativ, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, Sami Gh, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0