I am trying to format an email message that includes text from a string. I am able to send an email that includes string values, or format an email that has static text. I cannot seem to format an email that includes string values.
Looks to me like you're creating the same string about three times, then stepping on it when you're trying to add the URL escapes. Try this (not tested):
This still won't actually work, because you haven't specified a destination for the message when you create the urlString. But if it opens in MobileMail properly, it's easy to add that. If this doesn't work, post the console output.
Looks to me like you're creating the same string about three times, then stepping on it when you're trying to add the URL escapes. Try this (not tested):
I should clarify that my code example works fine in terms of sending a mail with a long line of text. What it doesn't do is providing any formatting to make it easier to read (e.g. bold, line breaks or returns). Any formatting examples I have tried to apply to it don't like the string inputs.
Quote:
Originally Posted by FlyingDiver
This still won't actually work, because you haven't specified a destination for the message when you create the urlString. But if it opens in MobileMail properly, it's easy to add that. If this doesn't work, post the console output.
I intentionally leave the destination blank. I want the user to input that.
I should clarify that my code example works fine in terms of sending a mail with a long line of text. What it doesn't do is providing any formatting to make it easier to read (e.g. bold, line breaks or returns). Any formatting examples I have tried to apply to it don't like the string inputs.
Ah. That wasn't clear. You should be able to get line breaks into the output by putting in carriage returns ('\r') where you want them, before its' URL encoded. If you want anything else, you're going to have to get a LOT more complicated. It'll have to be either MIME or HTML, and you're going to need to put in all the headers to declare a file type for the message body. Have you tried that?
I wonder if the "\r" is getting stripped out when it does the string encoding for the URL?
Quote:
Originally Posted by FlyingDiver
If you want anything else, you're going to have to get a LOT more complicated. It'll have to be either MIME or HTML, and you're going to need to put in all the headers to declare a file type for the message body. Have you tried that?
I did start down the HTML path, as this Nutsmuggling thread made it look easy. Which it probably is if you're just formatting static text. I can't find a way to insert a string from a variable within the HTML code though.
I did start down the HTML path, as this Nutsmuggling thread made it look easy. Which it probably is if you're just formatting static text. I can't find a way to insert a string from a variable within the HTML code though.
Print out that string before and after the URL encoding and see what you have.
This is really confusing. So when I do a NSLog on the final string which is the URL that triggers the email, the "%0D" which is a carriage return shows up.
Code:
2009-04-30 16:43:33.722 About Device[569:20b] mailto:?subject=My%20Subject%20&body=Device%20Name%3A%20Dennis%E2%80%99s%20iPhone%0DDevice%20Type%3A%20iPhone%0D
But it doesn't display that way in the Mail app on the iPhone, or the email that gets received. Just looks like a run-on text message.
Hi Joe. Thanks again for your suggestions.
This is really confusing. So when I do a NSLog on the final string which is the URL that triggers the email, the "%0D" which is a carriage return shows up.
Code:
2009-04-30 16:43:33.722 About Device[569:20b] mailto:?subject=My%20Subject%20&body=Device%20Name%3A%20Dennis%E2%80%99s%20iPhone%0DDevice%20Type%3A%20iPhone%0D
But it doesn't display that way in the Mail app on the iPhone, or the email that gets received. Just looks like a run-on text message.
Try '\n' for newline, or '\r\n' for the pair. I forget which is required in the mail spec.
For anyone playing along at home, there are two adjustments you will want to make to the code.
Remove the carriage returns from the HTML table code
Need a lowercase "S" on stringWithFormat
I appreciate your help and patience Joe. I will roll these improvements into my free About Device App. It throws all the device info into an email, so hopefully it will benefit lots of folks in the community (i.e. those collecting info from ad hoc/beta testers).
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"Default" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"Default"];
// Fill out the email body text
NSString *emailBody = [NSString stringWithString:[webView stringByEvaluatingJavaScriptFromString:@"document. documentElement.innerHTML"]];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewCont roller*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
webView.hidden = NO;