GMail API : unable to add an attachment in a draft

前端 未结 3 1637
不思量自难忘°
不思量自难忘° 2021-01-15 19:40

I am able to create simple html-only drafts using the GMail API.

But when I try to upload attachments it fails with the following error :

{
  \"code\         


        
相关标签:
3条回答
  • 2021-01-15 20:11

    I think that code is reasonable. Can you provide the output from the email.writeTo(System.out) to confirm? Seems like a bug in the Gmail API.

    Is this repeatable for any specific user? (Does it always fail or will it eventually work?)

    Does it happen for all users or only certain users (e.g. does it work for gmail.com users and not for Google Apps users)?

    0 讨论(0)
  • 2021-01-15 20:25

    Try this hope so its works first put text content and after that html content its display properly

    MimeBodyPart textPart = new MimeBodyPart();
            textPart.setText("This is actual message", "utf-8");
    
            MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setContent("<h1>This is a test</h1>"
                    + "<img src=\"http://www.rgagnon.com/images/jht.gif\">", "text/html; charset=utf-8");
            Multipart multipart = new MimeMultipart();
    
            multipart.addBodyPart(textPart);<--first 
            multipart.addBodyPart(htmlPart);<--seocnd 
            message.setContent(multipart)
    
    0 讨论(0)
  • 2021-01-15 20:26

    Problem solved by itself the next day ! I don't know if the GMail API team fixed something or if it was a temporary bug.

    0 讨论(0)
提交回复
热议问题