我正在从 iphone 应用程序发送电子邮件,我希望发送到的电子邮件应该是 var emailTO 具有的值或地址应该自动在 TO 中。
NSString*emailTO=@"ali@yahoo.com";
[picker setRecipients:[NSArray arrayWithObject:emailTO]];
但它不知道如何以这种方式实施谢谢
试试用这个...
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.");
}
试试这个。希望对您有所帮助。请注意,您需要将 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
。
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setToRecipients:[NSArray arrayWithObject:[NSString stringWithFormat:@"%@,@"ur Receipent data"]]]];
如果要打开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];
试试这个
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[picker setRecipients:[NSArray arrayWithObject:@"your email address"]];
[self presentViewController:mailViewController animated:YES completion:nil];
你应该使用
[picker setRecipients:[NSArray arrayWithObjects:emailTO,nil]];