Failed to send email via gmail api to multiple senders

We use the new gmail api on iOS to send emails, and everything works great for messages with single recipients. When we indicate 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 checked that the content we are sending is actually a valid rfc822 message.

+5
source share
4 answers

I had an exchange with the gmail team and they confirmed that this is actually a bug with their api. Not sure when it will be fixed, as they did not provide any details except on their radar.

-1
source

You should use the list in box in .

eg.

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

Gmail has a limit of bounce rates and recipients that you can send at the same time.

You cannot store multiple letters under one line. Placing one email address on each line will give better readability and prevent parsing errors.

Here is sample code in Java from Google. Hope this helps others understand:

  /** * 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: sending messages

Check out the first code example.

0
source

It was a regression, but we finished installing the fix on Monday, 2014-08-25.

0
source

I think you can do the following

get the "To" fields like " test1@example.com , test2@example.com "

then divide it by ','

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

then do it

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

I checked that it worked

0
source

Source: https://habr.com/ru/post/1200791/


All Articles