代码之家  ›  专栏  ›  技术社区  ›  Arun Sharma

邮件编写器地址问题

  •  0
  • Arun Sharma  · 技术社区  · 16 年前

    我从iPhoneOS参考库中找到了email composer示例代码。这里有一个密码

    代码:

    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
    NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
    

    我的问题是如何接受用户的输入?这里所有的电子邮件地址都是在代码中预先定义的。那么,to、cc、bcc、subject和body字段的ID是什么?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Pugalmuni Tom Tharakan    16 年前

    使用此代码。只将电子邮件地址作为用户输入。

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    
    picker.mailComposeDelegate = self;
    
    NSString *msgTitle = @"Sample Title";
    
        [picker setSubject:msgTitle];
    
    NSArray *toRecipients =[[NSArray alloc] init];
    
    NSArray *ccRecipients =[[NSArray alloc] init];
    
    NSArray *bccRecipients =[[NSArray alloc] init];
    
    [picker setToRecipients:toRecipients];
    
    [picker setCcRecipients:ccRecipients];  
    
    [picker setBccRecipients:bccRecipients];
    
        NSString *sum = @"The Email Body string is here";
    
    NSString *emailBody;
    
    emailBody = [NSString stringWithFormat:@"%@",sum];
    
    [picker setMessageBody:emailBody isHTML:YES];
    
    [self presentModalViewController:picker animated:YES];
    
    [picker release];
    
    
      -(void)launchMailAppOnDevice
      {
         NSString *recipients = @"mailto:?cc=,&subject=@";
    
         NSString *body = @"&body=";
    
         NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    
        email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    
      }
    

    祝你好运。

        2
  •  1
  •   Mihir Mehta    16 年前
    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
        controller.mailComposeDelegate = self;
        [controller setToRecipients:arr];
        [controller setCcRecipients:arr2];
        [controller setBccRecipients:arr3];
        [controller setMessageBody:@"Hello there." isHTML:NO];