google-apps-script to edit gmail subject line

2019-07-21 02:16发布

Here is the problem, and you can search and find lots of people who complain about it:

Let's say you sell something (e.g. run a small business selling on the internet) and you use PayPal to accept payments. PayPal sends every single notification of a payment with the exact same subject line "Notification of payment received".

So, if you receive a payment from Bobby Sue, and then you get a payment from Billy Jo, gmail shows:

Bobby Sue via PayPal(2)     Notification of payment received

and /nothing/ for Billy Jo. Billy is the (2), but it's buried in the same "thread"

And if you process Bobby Sue's order, and archive it, that archives Billy Jo's order as well. If you aren't careful, you can forget to ship anything for that order. And Billy don't like that.

I've searched long and hard for a setting or a way to keep gmail from doing that, or to change what PayPal sends in it's subject line. Seems to be a case of immovable object and irresistible force. *note: Yes, I know there is a setting in gmail that turns this "conversation view" off entirely. But that feature is very valuable for most emails. I only want to separate these paypal emails.

Any ideas?

My only idea is that gmail can be accessed by app scripts, and perhaps one could be written to find the transaction id in the email and tack it onto the subject when it arrives. But I can't find any example scripts that edit the subject line... Any idea if that is possible?

2条回答
霸刀☆藐视天下
2楼-- · 2019-07-21 02:40

I use PayPal email buttons and I pass as invoice parameter in the URL. When I receive a payment, the invoice ID is in the body.

Then I have Apps Script which processes periodically messages from PayPal. Simply it takes all Unread messages and looks for invoice ID. If invoice ID is found it marks the invoice in a spreadsheet as paid and marks the email in the thread as read.

And yes, you have to be careful with threading in Gmail at first the Gmail API is little bit counter-intuitive.

查看更多
手持菜刀,她持情操
3楼-- · 2019-07-21 02:54

Apps script won't be able to modify the subject line for an email as it arrives, it's not designed to modify inbound/outbound mail, only mail resting in the inbox to do tasks such as apply labels, or forward mail periodically.

If you're looking to modify Inbound mail, and you use Google Apps, custom routing rules might be helpful: https://support.google.com/a/answer/2368151?hl=en, but I doubt they will, as they don't tend to 'read' the message and attach an identifier.

In reality, the issue is that Paypal notifies you in an identical and hard to distinguish way every time you receive payment (No matter what your interface, Gmail or otherwise, it would be a lot handier to have your creditors name in the subject, saving you having to open the message). One solution you might find here is to leverage Paypals IPN infrastructure: https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/, but otherwise It's unlikely you'll find a solution in Apps script.

查看更多
登录 后发表回答