好的,
在iPhone上用表单发送电子邮件的常规协议(据我所知)是通过邮件应用程序发送电子邮件。下面的代码如下:
-(IBAction)sendEmail {
NSString *url = [NSString stringWithFormat: @"mailto:%@?body=%@", toEmail.text, content.text];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
//status.text = @"Sending...";
}现在,我希望它是一个只发送电子邮件的表单。我不希望它通过邮件或任何东西发送,我希望它从一个预定义的地址发送,例如mail@mydomain.com。
我该怎么做呢?
提前谢谢你。
亚历克斯
发布于 2010-07-16 15:24:44
在您的情况下,我建议您使用MFMailComposeViewController,它非常容易集成。我不确定是否可以从预定义的地址写电子邮件(我猜以这种方式发送电子邮件使用用户设备的默认邮件帐户)。
为了获得更大的灵活性,我想您必须使用SMTP。
我在我的项目中做的是:
-(void)displayComposerSheet{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:NSLocalizedString(@"MailSubject", @"")];
NSString *emailBody = NSLocalizedString(@"MailBody", @"");
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];}
还有一些你可以处理的委托方法。您可以在这里找到与MFMailComposeViewController相关的所有内容MFMailComposeViewController Class Reference
发布于 2010-07-18 08:33:48
MFMailCompose似乎确实是从您的设备默认帐户发送邮件的。
我在实现文件中使用这段代码将反馈电子邮件发送到我希望它们发送到的预定义地址。
它被设置为在单击时显示视图的按钮。
-(IBAction) Feedback:(id)sender {
NSArray *toRecipients = [NSArray arrayWithObject:@"xxxxxxxx"];
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.navigationBar.tintColor = [UIColor colorWithRed:.0 green:.1706 blue:.3804 alpha:1];
[picker setToRecipients:(NSArray *)toRecipients];
[picker setSubject:@"Feedback"];
[self presentModalViewController:picker animated:YES];
[picker release];
}我把x放在我应该有电子邮件地址的地方。这段代码还对我的邮件表单所在的导航栏进行了着色。
这需要MessageUI和MFMailComposerDelegate。
如果需要,您也可以包含多个要发送的电子邮件地址,因为它会将它们构建在一个数组中。
https://stackoverflow.com/questions/3262535
复制相似问题