Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Adamhoward1

macrumors newbie
Original poster
Mar 1, 2009
7
0
I have an application where I need to send data calculated by the program to an email address.

Does anyone have any extracts of code or links I can study to help me achieve this?

Thanks, Adam
 

cnstoll

macrumors 6502
Aug 29, 2010
254
0
Code:
MFMailComposeViewController *exporter = [[MFMailComposeViewController alloc] init];
exporter.mailComposeDelegate = self;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"data.txt"];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[exporter addAttachmentData:data mimeType:@"text/txt" fileName:@"data.txt"];

NSString *emailBody = @"Body";
[exporter setMessageBody:emailBody isHTML:NO];
[exporter setSubject:@"Subject"];
	
[self presentModalViewController:exporter animated:YES];
[exporter release];
 

Adamhoward1

macrumors newbie
Original poster
Mar 1, 2009
7
0
Code:
MFMailComposeViewController *exporter = [[MFMailComposeViewController alloc] init];
exporter.mailComposeDelegate = self;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"data.txt"];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[exporter addAttachmentData:data mimeType:@"text/txt" fileName:@"data.txt"];

NSString *emailBody = @"Body";
[exporter setMessageBody:emailBody isHTML:NO];
[exporter setSubject:@"Subject"];
	
[self presentModalViewController:exporter animated:YES];
[exporter release];



You’re a star. Thank you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.