5

我们在 iOS 上使用新的 gmail api 来发送电子邮件,一切都适用于单个收件人的消息。当我们在“to”字段中指定多个时,我们会收到以下错误:

Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn’t be completed. (Invalid to header)

我已验证我们发送的内容实际上是有效的 rfc822 消息。

4

5 回答 5

0

这是一个回归,但我们在 2014 年 8 月 25 日星期一完成了修复的部署。

于 2014-08-28T16:29:05.163 回答
0

我认为您可以执行以下操作

将“收件人”字段设为“test1@example.com, test2@example.com”

然后用','分割它

String mail1 = "test1@example.com";
String mail2 = "test2@example.com";

然后这样做

email.addRecipient(javax.mail.Message.RecipientType.TO,
                   new InternetAddress(mail1));
email.addRecipient(javax.mail.Message.RecipientType.TO,
                   new InternetAddress(mail2));

我检查了这个它有效

于 2014-09-29T03:51:53.153 回答
0

您应该在to字段中使用列表。

例如:

[ "liz6beigle@hotmail.com",
  "another.one@email.com" ]

Gmail 对您可以同时发送的退回邮件和收件人有限制。

您不能将多封电子邮件存储在一个字符串下。在每一行放置一个电子邮件地址将提供更好的可读性并防止解析错误。

这是来自 google 的 Java 代码示例。我希望它能帮助其他人理解:

 /**
   * Create a MimeMessage using the parameters provided.
   *
   * @param to Email address of the receiver.
   * @param from Email address of the sender, the mailbox account.
   * @param subject Subject of the email.
   * @param bodyText Body text of the email.
   * @return MimeMessage to be used to send email.
   * @throws MessagingException
   */
  public static MimeMessage createEmail(String to, String from, String subject,
      String bodyText) throws MessagingException {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    MimeMessage email = new MimeMessage(session);
    InternetAddress tAddress = new InternetAddress(to);
    InternetAddress fAddress = new InternetAddress(from);

    email.setFrom(new InternetAddress(from));
    email.addRecipient(javax.mail.Message.RecipientType.TO,
                       new InternetAddress(to));
    email.setSubject(subject);
    email.setText(bodyText);
    return email;
  }

Gmail API:发送消息

检查第一个代码示例。

于 2014-08-22T03:19:56.540 回答
0

You can use comma separated emails and loop through those emails

    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    MimeMessage email = new MimeMessage(session);
    Multipart multiPart = new MimeMultipart("alternative");
    email.setFrom(new InternetAddress(from));


    String to = "xyz@gmail.com,sjaksks@gmail.cm,hysrtt@gmail.com";
    String[] split = to.split(",");
    for(int i=0;i<split.length;i++) {
        email.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(split[i]));
    }


    email.setSubject(subject);

    MimeBodyPart textPart = new MimeBodyPart();
    textPart.setText(text, "utf-8");

    MimeBodyPart htmlPart = new MimeBodyPart();
    htmlPart.setContent(html, "text/html; charset=utf-8");

    multiPart.addBodyPart(textPart);
    multiPart.addBodyPart(htmlPart);
    email.setContent(multiPart);
    return email;
于 2019-12-18T09:03:34.937 回答
-1

我与 gmail 团队进行了交流,他们确实确认这实际上是他们 api 的错误。不知道什么时候会修复,因为他们没有提供更多细节,但它在他们的雷达上。

于 2014-08-25T18:12:44.013 回答