1

I have been switching from Google App Engine MailServier to the GMail API recently and I'm running into a strange issue: The emails are being sent out correctly, but on the recipients end the body is empty! (Subject is still there). I'm creating HTML emails with optional attachments and encode them using the snippet from the GMail API docs:

I'm using the snippet from the GMail API docs to encode the email:

  public static Message createMessageWithEmail(MimeMessage email)
      throws MessagingException, IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    email.writeTo(baos);
    String encodedEmail = Base64.encodeBase64URLSafeString(baos.toByteArray());
    Message message = new Message();
    message.setRaw(encodedEmail);
    return message;
  }

When looking into my "Sent" folder in GMail, I can see the message just fine (it is an HTML email body):

Received: from 889121556365-na05chj5g3il9flll2l3otqeh7q7ja22.apps.googleusercontent.com
    named unknown
    by gmailapi.google.com
    with HTTPREST;
    Thu, 18 Jun 2015 05:29:12 -0400
From: daniel.florey@gmail.com
To: daniel.florey@floreysoft.net
Message-Id: <CAHWc4t9o6gpRs_HT0Y8E1szJtDTwfSMS7OH+jVro-LiA1kBLJw@mail.gmail.com>
Subject: Test
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_1_15413936.1434619752068"
Date: Thu, 18 Jun 2015 05:29:12 -0400

------=_Part_1_15413936.1434619752068
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64


------=_Part_1_15413936.1434619752068
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64

TnVyIGVpbiBUZXN0ITxkaXY+PGJyPjwvZGl2PjxkaXY+PGZvbnQgc2l6ZT0iNiI+SGFoYWhhITwv
Zm9udD48L2Rpdj4=
------=_Part_1_15413936.1434619752068--

On the recipients end the same message is empty:

Delivered-To: daniel.florey@floreysoft.net
Received: by 10.140.94.46 with SMTP id f43csp925254qge;
        Thu, 18 Jun 2015 02:29:13 -0700 (PDT)
X-Received: by 10.180.94.39 with SMTP id cz7mr61405623wib.66.1434619752847;
        Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Return-Path: <daniel.florey@gmail.com>
Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com. [2a00:1450:400c:c05::233])
        by mx.google.com with ESMTPS id ju2si35306720wid.33.2015.06.18.02.29.12
        for <daniel.florey@floreysoft.net>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Received-SPF: pass (google.com: domain of daniel.florey@gmail.com designates 2a00:1450:400c:c05::233 as permitted sender) client-ip=2a00:1450:400c:c05::233;
Authentication-Results: mx.google.com;
       spf=pass (google.com: domain of daniel.florey@gmail.com designates 2a00:1450:400c:c05::233 as permitted sender) smtp.mail=daniel.florey@gmail.com;
       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Received: by wicgi11 with SMTP id gi11so7511413wic.0
        for <daniel.florey@floreysoft.net>; Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=from:mime-version:date:message-id:subject:to:content-type;
        bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
        b=aYXfdO2NjbNXjQglJuER7ul/PfgQ84kxfMtDvUr4XEYuYEEhOZzWTiBj4Aedq8xtrH
         5upGVtwKjHVc0R36BcFUD0tTq5IXLXsESIMEXL0pV0KJCFnXvMRCC+rn0uUzbCVWcSp4
         LG8RxP9YTWRMhWQUattO/vI43kV34EMLax+irhY+98pXkaHHrNd5+GGO2OMzdcRPOpCg
         gZ9bdQeEDsSrW4YJrxdKA/hJfCh6ceZ9mDgeRPiD+tC9AibhPK1QDqM8SKzh1QRoSZtl
         yPGyJWGUXYMM9o7XaCh8ZenKLvd/AdTF2oAbwyqXnycAvOZqqj03x4sA38o5c4fEjkIQ
         rAxQ==
X-Received: by 10.180.72.176 with SMTP id e16mr26991312wiv.12.1434619752466;
 Thu, 18 Jun 2015 02:29:12 -0700 (PDT)
Received: from 889121556365-na05chj5g3il9flll2l3otqeh7q7ja22.apps.googleusercontent.com
 named unknown by gmailapi.google.com with HTTPREST; Thu, 18 Jun 2015 05:29:12 -0400
From: daniel.florey@gmail.com
MIME-Version: 1.0
Date: Thu, 18 Jun 2015 05:29:12 -0400
Message-ID: <CAHWc4t9o6gpRs_HT0Y8E1szJtDTwfSMS7OH+jVro-LiA1kBLJw@mail.gmail.com>
Subject: Test
To: daniel.florey@floreysoft.net
Content-Type: text/plain; charset=UTF-8

The content type has been switched to text/plain?! Any ideas?

dflorey
  • 1,828
  • 3
  • 19
  • 31
  • Are you encoding on base64 then replace + with - and / with _ ? check this link http://tools.ietf.org/html/rfc2387 for MIME Multipart/Related Content-type .Also, check this link http://stackoverflow.com/questions/27895290/why-the-gmail-api-sends-html-emails-as-plain-text for the reason content-type is text/plain – SGC Jun 18 '15 at 17:13
  • I guess I do not understand your suggestion. Can you elaborate? I've added my code snippet for encoding to the question. It is taken from the GMail API docs. – dflorey Jun 19 '15 at 14:46
  • @dflorey Are you sure the other mail client you are looking at the mail in can handle HTML? Since you have no plain text version of your mail, a plain text mail service might not display anything. Have you tried mailing yourself (daniel.florey@gmail.com) and viewing it in the regular Gmail client? – Tholle Jun 22 '15 at 15:35
  • Yes, I'm opening the email in GMail. It looks ok in my sent folder but in the target email account it is empty. – dflorey Jun 23 '15 at 14:11

0 Answers0