MFMailComposeViewController isn't let the user input an email - iphone

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];

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];
}

Show Mail Composer When Cell of Table View Is Selected

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

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

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.

Is it possible to Prevent TO fileld to be edit in MFMailComposeViewController

in my Application i am using MFMailComposeViewController for emails...
I am Adding to Field in it programmaticly... I want To prevent user to edit the TO field,
User can't change TO field's email address... I am not able to find neither i know if it is possible or not
It is not necessary but still code is
NSArray *arr = [NSArray arrayWithObject:Emailstr];
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:arr];
[controller
[controller setMessageBody:#"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
It's not possible.