电子邮件功能不正常

时间:2012-01-05 06:19:07

标签: iphone

我已使用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:@"m.garg@ldh.01s.in"]; 
    [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];
    }
}

感谢所有人。

2 个答案:

答案 0 :(得分:0)

只需尝试这样的事情:

 if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
[controller setToRecipients:[NSArray arrayWithObject:@"123@abc.com.pk"]];
    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];
  }

答案 1 :(得分:-2)

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

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