Android:使用gmail-api获取电子邮件

时间:2015-10-14 12:53:53

标签: android gmail-api

我收到原始格式的邮件。然后通过

得到了Mimemessage
MimeMessage email = new MimeMessage(session, new ByteArrayInputStream(emailBytes));

现在email.getSubject正在返回正确的值但是 email.getReceivedDate为null

请解释一下这种行为。这是解码邮件不同部分的正确方法

com.google.api.services.gmail.model.Message fullMessage = mService.users().messages().get(acct.sEmail, message.getId()).setFormat("raw").execute();
                Properties props = new Properties();
                idg.javax.mail.Session session = idg.javax.mail.Session.getDefaultInstance(props, null);

                byte[] emailBytes = com.google.api.client.util.Base64.decodeBase64(fullMessage.getRaw());
                try {
                    idg.javax.mail.internet.MimeMessage email = new idg.javax.mail.internet.MimeMessage(session, new ByteArrayInputStream(emailBytes));
                    Log.i("Received date","is" + email.getReceivedDate() + message.getId());
                    Log.i("subject", "is" + email.getSubject());

                } catch (MessagingException e) {
                    e.printStackTrace();
                }

1 个答案:

答案 0 :(得分:0)

是的,您可以将#prgma mark - UITableViewDelegate Methods -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *stringCell = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.yourTextField.tag = indexPath.row; return cell; } #prgma mark - UITextFieldDelegate Methods - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSUInteger index = textField.tag; UITextField *nextTextField = (UITextField*)[self.view viewWithTag:index+1]; [nextTextField becomeFirstResponder]; return YES; } 用于getReceivedDate(),是的,当然,这是检索邮件不同部分的值的更好方法。

这是检索MimeMessageUsers MimeMessage

这是为了获得邮件的不同属性:MimeMessage Properties