I have app that user contact me
The problem is that the users can put any email address, but I want to lock or do something to setToRecipients so that user can't make any change in this field.
Here is my code
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"123#abc.com", nil]];
[composer setSubject:#"subject here"];
[composer setMessageBody:#"message here" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
Any help or guide !!
thanx & regards
You can't as MFMailComposeViewController does not provide that functionality.
By the look of it, you can't. And the reason is that apple has safety protection to ensure you app doesn't auto send spam emails, in their point of view, it's the user should always have flexibility to choose where the email goes to.
Related
How can I add video/image/audio as an attachment programmatically in the email in iPhone app iPhone and how can I add Signature? I think it can be done by using html tags but how it can be done. Can you please any sample code for this.
Thanks-
To send attachments: You can use MFMailComposeViewController to send attachments from your app.
1. Add MessageUI framework, and do #import <MessageUI/MFMailComposeViewController.h>
2. In your email button action or however you are sending email, add :
if([MFMailComposeViewController canSendMail]) //IMPORTANT: check if mail can be sent to avoid crash
{
MFMailComposeViewController*mailController=[[MFMailComposeViewController alloc] init];
NSURL*yourUrl=[NSURL fileURLWithPath:yourFilePath];
NSData*attachData=[NSData dataWithContentsOfURL:yourUrl];
mailController.mailComposeDelegate=self;
[mailController addAttachmentData:attachData mimeType:#"yourExtension" fileName:#"yourFileName.yourExtension"];
[mailController setSubject:#"Test Subject"];
[mailController setTitle:#"Test Title"];
if(mailController!=nil)
{
[self presentModalViewController:mailController animated:YES];
}
[mailController release];
}
else //give a prompt showing no mail accounts found
{
UIAlertView*emailAlert=[[UIAlertView alloc] initWithTitle:#"No Email Account Found." message:#"Please set an email account." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[emailAlert show];
[emailAlert release];
}
To set signature: I guess it uses the signature relative to the mail account that has been set. Sorry no idea on how to change it programmatically.
I have the following line of code,
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:APP_NAME];
[picker addAttachmentData:pdfData mimeType:#"pdf" fileName:pdfFileName];
NSString *emailBody = #"";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
But iPad just stuck at the first line of the code.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
When i put the break point on the another line it does not come to the second line of code it is just stuck and does not open MailCompserSheet and it is hung.
This problem appears only on iOS version 5.1 in iPad.
So anyway have idea what to do?
I guess you might not have configured mail in your iPad.
So before initializing the class MFMailComposeViewController, call MFMailComposeViewController's + (BOOL)canSendMail to check whether you can be able to send mail with the device or not.
My app generates information from textfields to a uitextview, i was wondering how i could send this information on a email when the user clicks a button.
The mail application should open and it will have the contents of the uitextview in the body of the email.
Many Thanks
You have to do it with MFMailComposeViewController. Here's the code:
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
[composer setSubject:#"My Subject"];
[composer setMessageBody:#"Email Body" isHTML:YES];
[self presentModalViewController:composer animated:YES];
[composer release];
Just replace #"My Subject" with your real subject and #"Email Body" with your TextView's contents. You can also set To, Cc and Bcc fields and add some attachments via this class.
You can also check if app can send an email by using:
[MFMailComposeViewController canSendMail];
E.g. if user didn't configure his email accounts, this function will return NO.
More info about sending emails from your app you can find in MFMailComposeViewController Class Reference.
I usually use the below code to allow the user to submit feedback on my apps. However for some reason in my OpenGL app the below code has a problem. It opens the email form correctly, however the form is locked - i.e the user can't actually edit the body of the text. Can anybody spot why this is happening ?
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Feedback on Stop That Bomb Free !"];
NSArray *toRecipients = [NSArray arrayWithObject:#"anemail#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody =
[NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[inputController presentModalViewController:picker animated:YES];
[picker release];
From reading your code I can find some things you should change:
Replace:
NSString *emailBody = [NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
With:
NSString *emailBody = #"Hi Martin, I would like to make the following comment : ";
As you are not using any formatting; you dont need to call the class method to create the simple string.
The other thing you can change is the fact that you message does not contain HTML.
So you dont need isHTML:YES.
I have tested this successfully on a sample app.
I imagine the problem is with the view controller presenting the view, rather than the messageUI view.
Using the code below, I'm bringing up a person picker so the user can choose either a phone or an email address. I've set the displayable properties to Email and Phone, but the "Ringtone" property is visible in the phone group. Given the purpose of this instance of Person picker, the Ringtone choice makes absolutely no sense to display here. Anyone know how to get rid of it in the phone group?
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
NSArray *propertiesToShow = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
[picker setDisplayedProperties:propertiesToShow];
[picker setPeoplePickerDelegate:self];
[self presentModalViewController:picker animated:YES];
[picker release];