Show Mail Composer When Cell of Table View Is Selected - iphone

I am trying to get my table view to present a mailcomposerviewcontroller when a cell is selected. I have tried using:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set up recipients
if ([arryData objectAtIndex:0]) {
[picker setSubject:#"To You"];
NSArray *toRecipients = [NSArray arrayWithObject:#"emailaddress#here.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = #"From Me";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
Yet, this gets me a crash and
which is waiting for a delayed presention of <MFMailComposeViewController:

Your code snippet seems to be fine here.
Still go through these steps again if you have missed something for that matter.
http://www.roseindia.net/answers/viewqa/Mobile-Applications/18176-iPhone-MFMailcomposeviewcontroller-example.html
I hope it helps you!
Cheers!!

It is better to check first if the device is configured to sent mails. You can see this link

Related

can't set Mailto field in MFMailComposeViewController in iphone

I have write code to send mail on button click.But i have email id programatically.
I have output like this.
email#gmail.com Send MailButton
Now when i click on Send MailButton then it open MFMailComposeViewController but to field is empty.Here email#gmail.com is change dynamically it's not fixed.
My code is
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([MFMailComposeViewController canSendMail])
{
NSString *emailBody;
emailBody=self.shareString;
//NSLog(#"EMail Body ---- %#",emailBody);
[picker setMessageBody:emailBody isHTML:YES];
[picker becomeFirstResponder];
[self presentModalViewController:picker animated:YES];
}
What should be change here required?
Use following code:
NSArray *tempArray = [[NSArray alloc] initWithObjects:#"abc#gmail.com", nil];
[picker setToRecipients:tempArray];
It's working properly for me.
Thanks,
Hemang.
Well you need to create an array for this first.
-(void)displayComposerSheetEmailUs{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Hello from the App!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"abc#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = #"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}

MFMailComposeViewController canSendMail change alert if returned no

I use MFMailComposeViewController canSendMail in my app everything works great but if there are no accounts on the iPhone or iPad it returns a standard alertview what I would like to change. If I put a alert in the else it will return 2 alerts. Is there a way to change the standard alert it returns? Or at least change the text in it?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail]) {
controller.mailComposeDelegate = self;
controller.navigationBar.tintColor = [UIColor grayColor];
NSArray *toRecipients = [NSArray arrayWithObject:#"info#info.nl"];
[controller setToRecipients:toRecipients];
[controller setSubject:#"bericht van info"];
[self presentModalViewController:controller animated:YES];
[controller release];
}
else {
}
try one thing.. Move your MFMailComposeViewController initialization code inside the canSendMail block.
Move the alloc of the 'MFMailComposeViewController' inside the if:
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
controller.navigationBar.tintColor = [UIColor grayColor];
NSArray *toRecipients = [NSArray arrayWithObject:#"info#info.nl"];
[controller setToRecipients:toRecipients];
[controller setSubject:#"bericht van info"];
[self presentModalViewController:controller animated:YES];
[controller release];
} else {
// Display custom alert here.
}
You can check if the device can send emails with
[MFMailComposeViewController canSendMail]
And, if not, show the dialog in your side

Mail Composer Issue

Is there a way to get the "from" address of Mail and display it in MFMailComposeViewController?
Is it possible?
Any way to do that..
Please help....
This will fill your MFMailComposeViewController:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// Set up subject
[picker setSubject:mailSubjectString];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:recieverMailAdress];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody = bodyString;
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
Edit:
I think you should have an look to skpsmtpmessage

MFMailComposeViewController isn't let the user input an email

I've configured a simple MFMailComposeViewController below. If I populate the setToRecipients, everything works fine, the email is sent. If I do not populate the setToRecipients, the mail composer window pops up but all fields remain non-editable.
I thought the MFMailComposeViewController would allow the user to edit the email before sending? Is this possible using the standard controls?
- (IBAction) sendEmail
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:[NSString stringWithFormat:#"Receipt Email - %#",[self.labelDate text]]];
NSString *emailBody = #"This is the message body";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
Never mind guys.... I hadn't resigned first responder of the parent view >.< Resolved by adding [self.parentViewController resignFirstResponder]; [self becomeFirstResponder];

iphone mailcomposer

i have my tabbar and i can hide this tab bar by the following code below but when tapping cancle of iphone mail composer does not return to the default screen can you please guide how can i do this
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#""];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#""];
NSString *emailBody = #"";
[picker setMessageBody:emailBody isHTML:NO];
//[self presentModalViewController:picker animated:YES];
UIViewController *xyz=(UIViewController*)[myMarketsVicAppDelegate getMainTabbarRef];
[xyz presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You must have to implement following Delegates.
UINavigationControllerDelegate
MFMailComposeViewControllerDelegate,
Like this
<MFMailComposeViewControllerDelegate,UINavigationControllerDelegate>.
Above might be an issue, because - If you have not implemented above delegate, It will give you compile time warnings but however it will execute.