代码:
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:@"Sample Subject"];
[mail setMessageBody:@"Here is some main text in the email!" isHTML:NO];
[mail setToRecipients:@[@""]];
[self presentViewController:mail animated:YES completion:NULL];
} else {
NSLog(@"This device cannot send email");
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result
{
switch (result) {
case MessageComposeResultCancelled:
break;
case MessageComposeResultFailed:
{
UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[warningAlert show];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
我使用MFMailComposeViewController发送邮件。 即使我收到成功消息,接收方也不会收到我的邮件。
我错过了什么?
答案 0 :(得分:0)
Errrr,真的吗?
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
. . .
[mail setToRecipients:@[@""]];
您尚未设置“收件人”电子邮件地址,并且您抱怨电子邮件尚未到达..?
试试这个:硬代码一个电子邮件地址,使用“arrayWithObject”,看看电子邮件是否现在发送:
NSString *emailAddress = @"mike@isomewhere.com";
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
. . .
[mail setToRecipients:[NSArray arrayWithObject:emailAddress]];