2011-08-19 66 views

回答

5

在Apple的文檔中查看MFMailComposeViewController。您可以使用它像這樣:

MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init]; 
controller.delegate = self; 
[controller setMessageBody:<#yourBody#> isHTML:<#isHTML#>]; 
[self presentModalViewController:controller animated:YES]; 
[controller release]; 

不要忘了在你的.h文件中添加#import <MessageUI/MessageUI.h>。它會調用委託中的方法告訴您何時取消或發送電子郵件(成功與否)。讓我知道這是否適合你。

9

爲什麼不直接在應用程序中打開電子郵件編輯器?

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 

[mailController setSubject:@"my subject"];     
[mailController setMessageBody:@"my message" isHTML:NO]; 

mailController.mailComposeDelegate = self; 

UINavigationController *myNavController = [myViewController navigationController]; 

if (mailController != nil) { 
    if ([MFMailComposeViewController canSendMail]){ 
     [myNavController presentModalViewController:mailController animated:YES]; 
    } 
} 

[mailController release]; 
5
NSString *body = @"Hello Mail"; 
NSString *mailtoURLString = [NSString stringWithFormat:@"mailto:?body=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailtoURLString]]; 

或者,如Mihai建議,看看MFMailComposeViewController它允許您發送電子郵件而無需離開你的應用程序。

3

以下方法用於向用戶發送郵件。

-(void)sendMail:(UIImage *)image 
{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; 
    picker.mailComposeDelegate = self; 

    // Set the subject of email 
    [picker setSubject:@"Picture from my iPhone!"]; 

    // Add email addresses 
    // Notice three sections: "to" "cc" and "bcc" 
    [picker setToRecipients:[NSArray arrayWithObjects:@TO mailID1",@TO mailID2", nil]]; 
    [picker setCcRecipients:[NSArray arrayWithObject:@"CC MailID"]]; 
    [picker setBccRecipients:[NSArray arrayWithObject:@"BCC Mail ID"]]; 

    // Fill out the email body text 
    NSString *emailBody = @"I just took this picture, check it out."; 

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

    // Create NSData object as PNG image data from camera image 
    NSData *data = UIImagePNGRepresentation(image); 

    // Attach image data to the email 
    // 'CameraImage.png' is the file name that will be attached to the email 
    [picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"]; 

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

    // Release picker 
    [picker release]; 
} 
0
NSString *textToShare = @"http:yourmail.com/"; 

NSArray *objectsToShare = @[textToShare]; 

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil]; 

NSArray *excludeActivities = @[UIActivityTypeAirDrop,UIActivityTypeSaveToCameraRoll]; 

activityVC.excludedActivityTypes = excludeActivities; 
[activityVC setValue:@"yourmail" forKey:@"subject"]; 

[self presentViewController:activityVC animated:YES completion:nil]; 
相關問題