scarletyy / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Mails sent via Gmail API won't arrive to Gmail accounts. #890

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-api-java-client (e.g. 1.15.0-rc)?
google-api-services-gmail-v1-rev3-java-1.18.0-rc 14.25.10

Java environment (e.g. Java 6, Android 2.3, App Engine)?
Android 4.4

Describe the problem.
I wrote code below to send mail using new Gmail API.
I ran the code, and mails were sent to my private e-mail accounts successfully.
But only Gmail accounts won't receive the mails sent via Gmail API, even though 
the mails were saved in sender's Gmail sent box.

    public static boolean sendMail(Gmail service, String from, List<String> to, String title, String body) {
        if (service == null) {
            return false;
        }
        Message message = new Message();

        StringBuilder builder = new StringBuilder();
        builder.append("From: ");
        builder.append(from);
        builder.append("\nTo: ");
        if (to != null) {
            int toSize = to.size();
            for (int i = 0; i < toSize; i++) {
                String tmp = to.get(i).replace(",", "");
                builder.append(tmp);
                if (i < toSize - 1) {
                    builder.append(", ");
                }
            }
        }
        builder.append("\nDate: ");
        SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
        String date = sdf.format(new Date());
        builder.append(date);
        builder.append("\nMIME-Version: 1.0\nSubject: =?ISO-2022-JP?B?");
        if (title != null) {
            try {
                builder.append(Base64.encodeBase64URLSafeString(title.getBytes("ISO-2022-JP")));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        builder.append("?=");
        builder.append("\nContent-Type: text/plain; charset=ISO-2022-JP;");
        builder.append("\nContent-Transfer-Encoding: 7bit");
        builder.append("\n\n");
        builder.append(body);

        String encodedEmail = Base64.encodeBase64URLSafeString(builder.toString().getBytes());

        message.setRaw(encodedEmail);

        boolean result = false;

        try {
            message = service.users().messages().send("me", message).execute();
            result = true;
        } catch (UserRecoverableAuthIOException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result;
    }

How would you expect it to be fixed?
The mails sent via Gmail API arrive to Gmail accounts.

Original issue reported on code.google.com by tanishir...@gmail.com on 9 Jul 2014 at 11:32

GoogleCodeExporter commented 9 years ago
Hi, this looks like an issue of the Gmail API. For any API related questions, 
we recommend you to ask on StackOverflow: 
http://stackoverflow.com/questions/tagged/gmail

This forum is for issues related to the runtime library.

Original comment by wonder...@google.com on 9 Jul 2014 at 5:39

GoogleCodeExporter commented 9 years ago
Using the gmail-api tag os StackOverflow would be the best way to get a 
response on this issue.

http://stackoverflow.com/questions/tagged/gmail-api

Original comment by arthurth...@google.com on 14 Jul 2014 at 9:03

GoogleCodeExporter commented 9 years ago
Thank you for your comments.

The issue seemed to be solved on seeing below.
http://stackoverflow.com/questions/24666489/sending-email-from-gmail-api-not-rec
eived-but-shown-in-sent-folder

Original comment by tanishir...@gmail.com on 16 Jul 2014 at 4:59

GoogleCodeExporter commented 9 years ago

Original comment by wonder...@google.com on 16 Jul 2014 at 5:38