IOS developmentOfEmail sendingThe Code is the content to be introduced in this article,Email sendingThe function is provided by MessageUI Framework, which is the simplest box in the iPhone SDK. It consists of a class, A View Controller, and a protocol.
1. Create a View Controller:
- MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
- mc.mailComposeDelegate = self;
Ii. Set Email Subject:
- [mc setSubject:@"Hello, World!"];
3. Set recipients. There are three types of recipients:
1. Set the primary recipient
- [mc setToRecipients:[NSArray arrayWithObjects:@"zhuqi0@126.com",
- "@dave@iphonedevbook.com", nil];
2. Set cc
- [mc setCcRecipients:[NSArray arrayWithObject:@"zhuqil@163.com"]];
3. Set bcc
- [mc setBccRecipients:[NSArray arrayWithObject:@"secret@gmail.com"]];
4. Set the email subject in two formats.
One is plain text
- [mc setMessageBody:@"Watson!!!\n\nCome here, I need you!" isHTML:NO];
One is in html format.
- [mc setMessageBody:@"<HTML><B>Hello, Joe!</B><BR/>What do you know?</HTML>"
- isHTML:YES];
5. Add attachments
Adding an attachment requires three parameters: an attachment of the NSData type, a mime type, and an attachment name.
- NSString *path = [[NSBundle mainBundle] pathForResource:@"blood_orange" ofType:@"png"];
- NSData *data = [NSData dataWithContentsOfFile:path];
- [mc addAttachmentData:data mimeType:@"image/png" fileName:@"blood_orange"];
Vi. View presentation
- [self presentModalViewController:mc animated:YES];
- [mc release];
VII. View Controller delegation Method
The delegate method of the mail View Controller is included in MFMailComposeViewControllerDelegate. Whether or not the user sends or cancels the message, whether the system can implementEmail sending,
Method mailComposeController: didFinishWithResult: error: gets called will be called.
- - (void)mailComposeController:(MFMailComposeViewController*)controller
- didFinishWithResult:(MFMailComposeResult)result
- error:(NSError*)error
- {
- switch (result){
- case MFMailComposeResultCancelled: NSLog(@"Mail send canceled...");
- break;
- case MFMailComposeResultSaved: NSLog(@"Mail saved...");
- break;
- case MFMailComposeResultSent: NSLog(@"Mail sent...");
- break;
- case MFMailComposeResultFailed: NSLog(@"Mail send errored: %@...", [error localizedDescription]);
- break;
- default: break;
- }
- [self dismissModalViewControllerAnimated:YES];
- }
Summary: AnalysisIOS developmentOfEmail sendingI hope this article will help you with the introduction of the Code!