2017-08-19 109 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客戶端庫。

相關問題