Search code examples
iphoneipadmfmailcomposer

Want to open mail setup in iphone whenever user doesnt have implemented any mail account in mail


I have implemented mail composer. But it opens mail composer whenever user had implemented mail account in iphone. My requirement is If user had not implemented mail accont , the mail setup should be opened.


Solution

  • Try this code...

          if ([mailClass canSendMail])
            {
                [self displayComposerSheet];
            }
            else
            {
                   //open mail set up
                [self launchMailAppOnDevice];
            }
    
    // Launches the Mail application on the device.
    -(void)launchMailAppOnDevice
    {
        NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
        NSString *body = @"&body=It is raining in sunny California!";
    
        NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
        email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    }