-1

我正在从 iphone 应用程序发送电子邮件,我希望发送到的电子邮件应该是 var emailTO 具有的值或地址应该自动在 TO 中。

     NSString*emailTO=@"ali@yahoo.com";


    [picker setRecipients:[NSArray arrayWithObject:emailTO]];

但它不知道如何以这种方式实施谢谢

4

6 回答 6

0

试试用这个...

NSArray *array = [NSArray arrayWithObject:@"ali@yahoo.com"];

        if ([MFMailComposeViewController canSendMail])
        {

            MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
            mailViewController.mailComposeDelegate = self;

            [mailViewController setToRecipients:array];

            [self presentViewController:mailViewController animated:YES completion:NULL];
        }

        else
        {

            NSLog(@"Device is unable to send email in its current state.");

        }
于 2013-05-30T06:38:08.560 回答
0

试试这个。希望对您有所帮助。请注意,您需要将 MessageUI 框架添加到您的应用程序中。

#import <MessageUI/MessageUI.h>

MFMailComposeViewController *mail = [[[MFMailComposeViewController alloc] init] autorelease];
mail.mailComposeDelegate = self;
[mail setToRecipients:[NSArray arrayWithObject:@"email@gmail.com"]];
[mail setSubject:@"Set Your Subject Here"];    
[self presentModalViewController:mail animated:YES];

使用MFMailComposeViewControllerDelegate protocol:委托函数来确认结果

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }
}

描述

setToRecipients:

将初始收件人设置为包含在电子邮件的“收件人”字段中。

- (void)setToRecipients:(NSArray*)toRecipients

参数 toRecipients 一个array对象NSString,每个对象都包含email address一个single recipient

于 2013-05-30T06:38:41.967 回答
0
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setToRecipients:[NSArray arrayWithObject:[NSString stringWithFormat:@"%@,@"ur Receipent data"]]]];
于 2013-05-30T06:51:05.240 回答
0

如果要打开iPhone电子邮件应用程序,请使用以下代码。因此,您无需添加MFMailComposeViewController.

NSString *subject = @"";

NSString *body = @"";

NSString *address = @"test@gmail.com";

NSString *cc = @"";

NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];

NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:url];
于 2013-05-30T07:16:57.763 回答
0

试试这个

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
                mailViewController.mailComposeDelegate = self;
                [picker setRecipients:[NSArray arrayWithObject:@"your email address"]];
                [self presentViewController:mailViewController  animated:YES completion:nil];
于 2013-05-30T07:37:04.713 回答
-1

你应该使用

[picker setRecipients:[NSArray arrayWithObjects:emailTO,nil]];
于 2013-05-30T06:33:15.980 回答