Send email

iPhone SDK Tips & Tricks

[UIApplication sharedApplication] openURL:[NSURK URLWithString:@”mailto:someone@email.com?subject=subject%20sample&body=body”]];

for iPhone OS 3:
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if([mailClass canSendMail])
{
MFMailComposeViewController *mailCompose = [[[MFMailComposeViewController alloc] init] autorelease];
mailCompose.mailComposeDelegate = self;
[mailCompose setToRecipients:[NSArray arrayWithObject:@"x@yahoo.com", @"y@yahoo.com"]];
[mailCompose setSubject:@"subject sample"];

//attachment
UIImage *myImage = [UIImage imageNamed:@"box.png"];
NSData *imageData = UIImageJPEGRepresentation(
myImage, 1);
[mailCompose addAttachmentData:imageData mimeType:@"image/png" fileName:@"box.png"];

[mailCompose setMessageBody:messageBody isHTML:YES];
[self presentModalViewController:mailCompose animated:YES];
}