2012-01-05 157 views
1

我已使用MFMailComposeViewController在我的代码中发送电子邮件。我也使用可达性代码来检查互联网连接。互联网连接工作正常。每当我用我的代码发送邮件时,我都会收到邮件已发送的消息。但我没有收到任何邮件。没有从应用发送的电子邮件。我不知道这背后的原因。如果有人知道如何摆脱这个问题,请为我提供一些解决方案。电子邮件功能无法正常工作

-(void)sendemail 
{ 
    emailBody = @""; 
    mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 
    [mail setSubject:@"Report"]; 
    NSURL *url = [NSURL URLWithString:imagePath]; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    [mail addAttachmentData:data mimeType:@"image/jpg" fileName:@"licence.png"]; 
    NSMutableString *breakline = [[NSMutableString alloc]init]; 
    [breakline appendString:[NSString stringWithFormat:@"<br>"]]; 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    [mail setToRecipients:toRecipients]; 
    emailBody = [emailBody stringByAppendingFormat:@"%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@",@"Name: ",namestr,breakline,@"Address: ", addresstr,breakline,@"Landmark: ",landmarkstr,breakline,@"City: ", citystr,breakline,@"State: ", statestr,breakline,@"PIN: ", pinstr,breakline,@"Contact No: ",phonestr,breakline,@"Licence:",licencestr,breakline,@"Email Id", emailstr]; 
    [mail setMessageBody:emailBody isHTML:YES]; 
    if (mail != nil) { 
     [self presentModalViewController: mail animated: YES]; 
     [mail release]; 
    } 
} 

谢谢大家。

+0

请检查是否data''有有效数据。 – Ilanchezhian 2012-01-05 06:45:07

+1

也检查我们是否可以使用'if([MFMailComposeViewController canSendMail])发送邮件' – Ilanchezhian 2012-01-05 06:47:02

回答

-2

我不知道你的“收件人”数组是否在发送邮件之前被释放。

当邮件编辑器视图控制器出现时,您的配方电子邮件是否显示在“发送到”字段中?

+0

是的,它显示在收件人选项中。 – Nitin 2012-01-05 06:58:57

0

简单地尝试这样的事:

if([MFMailComposeViewController canSendMail]) 
{ 
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
[controller setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; 
    controller.mailComposeDelegate = self; 
[controller setSubject:@""]; 
[controller setMessageBody:@"" isHTML:NO]; 
if (controller) [self presentModalViewController:controller animated:YES]; 
[controller release]; 
} 

,不要忘记添加下面的委托方法,返回到您的应用程序:

- (void)mailComposeController:(MFMailComposeViewController*)controller 
     didFinishWithResult:(MFMailComposeResult)result 
        error:(NSError*)error; 
{ 
if (result == MFMailComposeResultSent) { 
    NSLog(@"It's away!"); 
} 
[self dismissModalViewControllerAnimated:YES]; 
    }