Nik
Nik

Reputation: 3133

MFMailComposeViewController canSendMail returns YES but not sending mail in iOS

The following is my code to send an attachment in a mail. This works fine. I am able to send mails but I don't always receive the mails.

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

// Set the subject of email
[picker setSubject:@"My data file"];

// Add email addresses

[picker setToRecipients:[NSArray arrayWithObjects:emailId, nil]];


// Fill out the email body text
NSString *emailBody = @"Hello, \n Please find the data from the iOS app in the attachments.\n\n Thank you.\nMy Team.";

// This is not an HTML formatted email
[picker setMessageBody:emailBody isHTML:NO];

// Create NSData object from file
NSData *exportFileData = [NSData dataWithContentsOfFile:filePath];

// Attach image data to the email
[picker addAttachmentData:exportFileData mimeType:@"text/csv" fileName:  [self.CSVNameTextField text]];


// Show email view

if ([MFMailComposeViewController canSendMail]) {

    [self presentModalViewController:picker animated:YES];
}

Upvotes: 4

Views: 4002

Answers (3)

M.Yessir
M.Yessir

Reputation: 222

In my case i had to manually open up the iphone mail app, then mails were sent and received immediately.

Upvotes: 1

xapslock
xapslock

Reputation: 1129

After you send the Mail with your App go to the Mail-Software on your iPhone, you will most likely find the mail in the Outbox.

Cause the MFMailComposeViewController will just forward the Mail to the Mail-Software and it doesn't care what happens next to the message. So it's up to your Mail-Software how and when the Outbox will be updated.

Upvotes: 6

sam_smith
sam_smith

Reputation: 6093

I had the same problem, I found that it would go through the mail box and say it had sent and then nothing would come through.

About 20-30 minutes later the first one came through and then gradually the rest I sent came through too.

I don't know why it takes so long, if I find out I will edit this answer, but definitely wait up to an hour before assuming your code is broken.

Hope this helps someone who, like me, might be trawling their code over and over

Upvotes: 2

Related Questions