ios发送邮件

ios发送邮件

by 伍雪颖


第一种:

NSString *myEmail = @"[email protected]";
NSString *toemail = @"[email protected]";
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: @"[email protected]"];
    [mailPicker setToRecipients: toRecipients];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
    [mailPicker setCcRecipients:ccRecipients];
    
    // add a picture
    UIImage *addPic = [UIImage imageNamed: @"[email protected]"];
    NSData *imageData = UIImagePNGRepresentation(addPic);
    [mailPicker addAttachmentData: imageData mimeType: @"" fileName: @"Icon.png"];
    
    NSString *emailBody = @"<font size='4'>Dear:</font>";
    [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];
}

一般用第二种

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。