ios發送郵件 – iPhone手機開發技術文章 iPhone軟體開發教學課程

ios發送郵件

by 伍雪穎

第一種:

NSString *myEmail = @"3423423423@qq.com";
NSString *toemail = @"asdfasdf@gmail.com";
NSString *emailDetail = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=Feedback!&body=Dear:",toemail,myEmail];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailDetail]];

第二種:

- (void)displayMailPicker {
    MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
    mailPicker.mailComposeDelegate = self;
    [mailPicker setSubject: @"Feedback!"];
    NSArray *toRecipients = [NSArray arrayWithObject: @"3434234@qq.com"];
    [mailPicker setToRecipients: toRecipients];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"asdfa@gmail.com", nil];
    [mailPicker setCcRecipients:ccRecipients];
    
    // add a picture
    UIImage *addPic = [UIImage imageNamed: @"icon_logo@2x.png"];
    NSData *imageData = UIImagePNGRepresentation(addPic);
    [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"];
    
    NSString *emailBody = @"Dear:";
    [mailPicker setMessageBody:emailBody isHTML:YES];
    [self presentViewController:mailPicker animated:YES completion:nil];
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [self dismissViewControllerAnimated:YES completion:nil];
}

一般用第二種

發佈留言