2017-08-19 43 views
0

我正在使用下面的代码。它工作正常,电子邮件发送成功。但它将我的默认登录邮件作为from地址。我如何定制它?如何使用objective c在MessageUI中设置来自收件人?

- (IBAction)sendbutton:(id)sender { 
if ([MFMailComposeViewController canSendMail]) 
{ 

NSString *emailTitle = self.subjecttextfield.text; 
NSString *messageBody = self.messagetext.text; 
    NSString *recipents = self.totextfield.text; 
NSMutableArray * myarray =[[NSMutableArray alloc]initWithObjects:@"%@",recipents,nil]; 

MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init]; 
mc.mailComposeDelegate = self; 
[mc setSubject:emailTitle]; 
[mc setMessageBody:messageBody isHTML:NO]; 
[mc setToRecipients:myarray]; 

// Present mail view controller on screen 
[self presentViewController:mc animated:YES completion:NULL]; 
}} 
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 
switch (result) 
{ 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail cancelled"); 
     break; 
    case MFMailComposeResultSaved: 
     NSLog(@"Mail saved"); 
     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail sent"); 
     break; 
    case MFMailComposeResultFailed: 
     NSLog(@"Mail sent failure: %@", [error localizedDescription]); 
     break; 
    default: 
     break; 
} 
[self dismissViewControllerAnimated:YES completion:NULL];} 

回答

0

你不能。发件人地址是设置中的“默认”邮件帐户。如果你想改变它,你必须使用一个通用的SMTP客户端库。

相关问题