简体   繁体   中英

How do I get message attachments in Gmail for forwarded messages addressed to an external user?

I have a Java program utilizing the Gmail API that authenticates with our G Suite via OAuth 2.0, downloads all attachments for messages in a specific user's inbox, and processes said attachments.

I am experiencing a very specific issue where for some messages sent from certain fax servers that are being forwarded to the account, where the "to:" field is addressed to something other than the account itself, using

service.users().messages().get(userID, messageID).execute();

will not retrieve these attachments. This is even true if I am using the universal "me" identifier.

If I forward the message to myself and the "to:" field changes, the program is able to pick up on it, but not if it is addressed to someone else. This is a problem because these messages are addressed to an email that is outside of our G Suite domain. I have tried all methods of forwarding and filtering within Gmail, including forwarding to another provider like Yahoo, but automatic forwarding does not change the "to:"/deliveredto: field in the original email, and thus causes the same issue.

I have tried using a different method for authenticating, where I tried utilizing a Service Account for domain-wide delegation with the full Gmail scope, as referenced here Gmail API domain-wide delegation and following the exact steps outlined by the Google documentation.

The problem is, even when I use domain-wide delegation and specify the setServiceAccountUser as the fax user from the "to:" field, it says that is not a valid user, which makes sense as that is not a Gmail user or user within our domain, it is being forwarded from an external source we have no control over.

I have attempted to build a program that manually forwards these emails back to this platform account, but I run across the same issues as the service.users().messages().get(userID, messageID) method requires a userID and messageID.

Message message = service.users().messages().get("xxxxxxxxx@faxmail.vonage.com", messageID).execute();

Above is the section of code I've isolated where the .get() method is not allowing the program to get attachments for this external user, which seems to be directly defined by the "to:" field in the email - if I forward this email to myself and the "to:" changes to my user, it instantly is able to grab the attachment.

When I tried domain-wide delegation with a Service Account or changing the userID in the detailed method to the faxmail.vonage.com address, it would give me a 403 or 400 error - either complaining the user doesn't exist, or saying "Delegation denied for platform@xxxxxx.com"

If you are using G Suite you can use the Forwarding rules in the Control Panel to send all the emails coming for that address to whenever you want.

edit:

With the content compliance rules on the G Suite Admin Panel you can adjust the envelope information allowing you to change the "to" field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM