1

I have created a simple email sender using MFMailComposeViewController. I programmed it such a way that people will have a textField to fill up a mail address before MFMailComposeViewController is called.

When I tried to pass the content of the text field in to the

NSArray *toRecipents = [NSArray arrayWithObject:receipient];

method (recipient is a NSString), somehow, when the MFMailComposViewController is presented, it always gives

Error:"Is not a valid email address" 

and leaves the Recipient part empty.

If I change

NSArray *toRecipents = [NSArray arrayWithObject:receipient];

to

NSArray *toRecipents = [NSArray arrayWithObject:@"support@app.com"];

where I entered the address manually, it will work properly.

Anyone knows how do I do such that I can pass in an NSString variable without getting the invalid error?

PS:I did email validation, i have printed out the text as well to double check, the NSString is indeed "support@app.com", the same thing as i manually entered, but it just doesn't work.

For those who have tried MessageUI, please help to double check if i am making any silly mistakes

Thanks

Regards

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
progammingBeignner
  • 936
  • 1
  • 8
  • 19

1 Answers1

1

Your code is just fine. Try using arrayWIthObjects instead of arraywithObject:

  NSString *recipient =textField.text;
   NSArray *recipients = [NSArray arrayWithObjects:recipient, nil];

Use nil, after the recipient, and see if it works or not.

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109