2011-10-27 70 views

回答

1

您將需要使用MFMailComposeViewController類。下面是相關的部分從蘋果公司的MailComposer example

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
picker.mailComposeDelegate = self; 

[picker setSubject:@"Hello from California!"]; 

// Set up recipients 
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
[picker setToRecipients:toRecipients]; 

[self presentModalViewController:picker animated:YES]; 
[picker release]; 

的MailComposer樣本還說明了如何打開外部郵件程序:

NSString *recipients = @"mailto:[email protected]&subject=Hello from California!"; 
NSString *body = @"&body=It is raining in sunny California!"; 

NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body]; 
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]]; 
+0

請務必首先測試[MFMailComposeViewController canSendMail]。 – picciano

+0

感謝您的幫助。 – HardCode

0

當然可以。

- (void)emailExport:(NSString *)filePath 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    // Set the subject of email 
    [picker setSubject:@"My desired subject"]; 

    // Add email addresses 
    // Notice three sections: "to" "cc" and "bcc" 

    NSString *valueForEmail = @"[email protected]"; 
    NSString *valueForCCEmail = @"myCcEmail"; 
    if(valueForEmail == nil || [valueForEmail isEqualToString:@""]) 
    { 
     UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please set an email address before sending a time entry!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release];   

     return; 
    } 
    else { 
     [picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]]; 
    } 

    if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:@""]) 
    { 
     [picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]]; 
    } 

    // Fill out the email body text 
    NSString *emailBody = @"My email body text."; 

    // This is not an HTML formatted email 
    [picker setMessageBody:emailBody isHTML:NO]; 

    // Show email view 
    [self presentModalViewController:picker animated:YES]; 

    // Release picker 
    [picker release]; 
} 
相關問題