无法通过gmail api向多个发件人发送电子邮件(Unable to send email via gmail api to multiple senders)

编程入门 行业动态 更新时间:2024-10-26 18:25:07
无法通过gmail api向多个发件人发送电子邮件(Unable to send email via gmail api to multiple senders)

我们在iOS上使用新的gmail api发送电子邮件,并且对于单个收件人的邮件,一切都非常有用。 当我们在“to”字段中指定多个时,会出现以下错误:

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

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

We're using the new gmail api on iOS to send emails and everything works great for messages with single recipients. When we specify more than one in the "to" field, we get the following error:

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

I have verified the content we are sending is in fact a valid rfc822 message.

最满意答案

你应该在你领域使用一个列表。

例如:

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

Gmail有可同时发送的退回和收件人数限制。

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

这里是来自谷歌的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:发送消息

检查第一个代码示例。

I had an exchange with the gmail team and they did confirm that this is actually a bug with their api. Not sure when it will be fixed as they didn't provide any more details but it's on their radar.

更多推荐

本文发布于:2023-08-04 09:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1414858.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   发件人   发送电子邮件   api   gmail

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!