- (void)createEmail {
//Create a string with HTML formatting for the email body
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@""] retain];
//Add some text to it however you want
[emailBody appendString:@"Some email body text can go here
"];
//Pick an image to insert
//This example would come from the main bundle, but your source can be elsewhere
UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
//Convert the image into data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
//Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
//Add the encoded string to the emailBody string
//Don't forget the "" tags are required, the "" tags are optional
[emailBody appendString:[NSString stringWithFormat:@"
",base64String]];
//You could repeat here with more text or images, otherwise
//close the HTML formatting
[emailBody appendString:@""];
NSLog(@"%@",emailBody);
//Create the mail composer window
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:@"My Inline Image Document"];
[emailDialog setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];
}
http://stackoverflow.com/questions/1527351/how-to-add-an-uiimage-in-mailcomposer-sheet-of-mfmailcomposeviewcontroller-in-iph
or
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Setting up the Subject, recipients, and message body.
[mail setToRecipients:[NSArray arrayWithObjects:@"address@example.com",nil]];
[mail setSubject:@"iCostume"];
[mail setMessageBody:@"Your custom costume picture" isHTML:NO];
UIImage *pic = [self imageToShare];
NSData *exportData = UIImageJPEGRepresentation(pic ,1.0);
[mail addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Picture.jpeg"];
//Present the mail view controller
[self presentModalViewController:mail animated:YES];
}
//release the mail
[mail release];
No comments:
Post a Comment