Compose HTML email

Discussion in 'iPhone/iPad Programming' started by Labeno, Mar 9, 2009.

  1. macrumors member

    Joined:
    Jul 21, 2008
    #1
    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:mad:"<html>\n"];
    [body appendString:mad:"<body>\n"];
    [body appendString:mad:"\n"];
    [body appendString:[NSString stringWithFormat:mad:"<h4>Date %@</h4>\n", @"Mar 9 2009"]];
    [body appendString:mad:"<table border=\"1\" bgcolor=\"#ccffcc\" cellpadding=\"4\" cellspacing=\"0\">\n"];
    [body appendString:mad:"<tr>\n"];
    [body appendString:mad:" <td style=\"color:#ffffff; background-color:#003300; text-align:center\"><b>Date</b></td>\n"];
    [body appendString:[NSString stringWithFormat:mad:" <td>%@</td>\n", @"Mar 9 2009"]];
    [body appendString:mad:"</tr>\n"];
    [body appendString:mad:"\n"];
    [body appendString:mad:"</body>\n"];
    [body appendString:mad:"</html>\n"];
    NSString *body2 = [NSString stringWithFormat:mad:"%@", body];
    NSString *body3 = [body2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *subject2 = [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *mail_string = [NSString stringWithFormat:mad:"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:mad:"<h4>Date %@</h4>\n", @"Mar 9 2009"]];

    Anyone has any ideas for either issue?
    Thanks
     

Share This Page