PDA

View Full Version : Compose HTML email




Labeno
Mar 9, 2009, 06:25 AM
I'm trying to figure out two issues when emailing:

Issue 1: When try to compose the following, it starts the email tool where I can view the final html, and there are about 10 new lines between the header and the table. I would expect 1 new line:

[body appendString:@"<html>\n"];
[body appendString:@"<body>\n"];
[body appendString:@"\n"];
[body appendString:[NSString stringWithFormat:@"<h4>Date %@</h4>\n", @"Mar 9 2009"]];
[body appendString:@"<table border=\"1\" bgcolor=\"#ccffcc\" cellpadding=\"4\" cellspacing=\"0\">\n"];
[body appendString:@"<tr>\n"];
[body appendString:@" <td style=\"color:#ffffff; background-color:#003300; text-align:center\"><b>Date</b></td>\n"];
[body appendString:[NSString stringWithFormat:@" <td>%@</td>\n", @"Mar 9 2009"]];
[body appendString:@"</tr>\n"];
[body appendString:@"\n"];
[body appendString:@"</body>\n"];
[body appendString:@"</html>\n"];
NSString *body2 = [NSString stringWithFormat:@"%@", body];
NSString *body3 = [body2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *subject2 = [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *mail_string = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", recipient, subject2, body3];
NSURL *url = [[NSURL alloc] initWithString:mail_string];
[[UIApplication sharedApplication] openURL:url];

The second problem is that sometimes the email tool won't even start. This can be shown just by duplicating an existing line of HTML. For example, the following line was duplicated 3 times and the email app would no longer start:

[body appendString:[NSString stringWithFormat:@"<h4>Date %@</h4>\n", @"Mar 9 2009"]];

Anyone has any ideas for either issue?
Thanks