如何从iphone应用程序向所需用户发送邮件
我正在从iphone应用程序发送邮件 我希望用户在邮件中输入to字段,并将邮件发送给他们,而不是静态接收如何从iphone应用程序向所需用户发送邮件,iphone,xcode,Iphone,Xcode,我正在从iphone应用程序发送邮件 我希望用户在邮件中输入to字段,并将邮件发送给他们,而不是静态接收 - (void)onEmailResult { if ([[MFMailComposeViewController class] canSendMail]) { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailC
- (void)onEmailResult
{
if ([[MFMailComposeViewController class] canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Game"];
// Set up recipients
NSArray * toRecipients = [NSArray arrayWithObject:@"husain_2000@yahoo.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString * emailBody = [NSString stringWithFormat:@"My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
NSString *recipients = @"mailto:husain_2000@yahoo.com?&subject=Game";
NSString *body = [NSString stringWithFormat:@"&body=My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
}
应在iPhone中配置电子邮件 然后试试这个代码
- (void)onEmailResult
{
if ([[MFMailComposeViewController class] canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Game"];
// Leave recipients as blank
// Fill out the email body text
NSString * emailBody = [NSString stringWithFormat:@"My Score: %d/%d, My Time: %@", numberOfCorrectAnswer, [[[DataManager sharedInstance] questions] count], time];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
只需手动在地址字段中输入他们的电子邮件ID?如果我手动输入电子邮件ID,那么它将发送到应用程序中的那个邮箱,或者不发送,为什么不试试?请注意,它在simualtor上不起作用,您需要一个设置了邮件帐户的实际设备。