Sending data as an email

Discussion in 'iOS Programming' started by Adamhoward1, Dec 31, 2010.

  1. Adamhoward1 macrumors newbie

    Joined:
    Mar 1, 2009
    #1
    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
     
  2. cnstoll macrumors 6502

    Joined:
    Aug 29, 2010
    #2
    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];
    
     
  3. Adamhoward1 thread starter macrumors newbie

    Joined:
    Mar 1, 2009
    #3


    You’re a star. Thank you.
     
  4. Adamhoward1 thread starter macrumors newbie

    Joined:
    Mar 1, 2009

Share This Page