0

We are not allowed to use native mail functionality for sending emails.

Hence our native iPad app integrated MSGraph SDK for sending mails along with an attachment. MSGraphSDK used to verify the work user by getting authentication credentials.

NSArray *scopes = [kScopes componentsSeparatedByString:@","];
[self.authProvider connectToGraphWithClientId:kClientId scopes:scopes completion:^(NSError *error) {
                    if (!error) {
                        NSLog(@"Authentication successful.");
                        [self sendMailWithAttachments];
                    }
}];

From next time onwards, it will directly send the mails without asking work credentials.

[MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
self.graphClient = [MSGraphClient client];

MSGraphMessage *message = [self getSampleMessage];
MSGraphUserSendMailRequestBuilder *requestBuilder = [[self.graphClient me]sendMailWithMessage:message saveToSentItems:true];
MSGraphUserSendMailRequest *mailRequest = [requestBuilder request];
[mailRequest executeWithCompletion:^(NSDictionary *response, NSError *error) {
        if(!error){
}
}];

MSGraph SDK used to direct the authenticated page automatically if users are not authenticated or users authentication was not successful.

Now problem here is, users are trying to authenticate themselves and sending mails on first few times successfully. After that a month later or more, they trying to send the mails using this app. Unfortunately it does not respond anything.

wesley
  • 859
  • 5
  • 15
  • What authentication provider are you using? It sounds like you are having an issue with token refresh - You need to look at debugging messages. I recommend using Microsoft's ADALios library for authentication - There is information on their Github repository on how to enable debug logging. – Paulw11 May 17 '19 at 00:08
  • Thanks for your comment. I used NXOAuth2AuthenticationProvider as authentication provider. I even couldn't debug as it is happened after month gaps. For debug logging, please provide that Github link if possible. – wesley May 17 '19 at 10:09
  • I strongly suggest using this module - https://github.com/AzureAD/azure-activedirectory-library-for-objc It supports Azure AD conditional access and brokered authentication via the Microsoft Authenticator app - A much nicer experience in enterprise environments where that app is deployed. See the *Diagnostics* section in the readme in that repo for details on logging - However, there is a good chance that if you use Microsoft's library your issues will go away. – Paulw11 May 17 '19 at 10:14

1 Answers1

-1

Try Below Code:

NSString *titleEmail =  @"Your title";
NSString *msgBody = @"PFA";
NSArray *toRecipents = [NSArray arrayWithObject:@"xyz@gmail.com"];

NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, self.view.bounds, nil);
UIGraphicsBeginPDFPage();
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIGraphicsEndPDFContext();

MFMailComposeViewController *mailComposeVC = [[MFMailComposeViewController alloc] init];
mailComposeVC.mailComposeDelegate = self;
[mailComposeVC setSubject:titleEmail];
[mailComposeVC setMessageBody:msgBody isHTML:NO];
[mailComposeVC addAttachmentData:pdfData mimeType:@"application/pdf" fileName:@"MY.pdf"];
[mailComposeVC setToRecipients:toRecipents];

[self presentViewController:mailComposeVC animated:YES completion:NULL];