# Access Gmail account via a local socks5 proxy and delete some emails based on specific criterion

**URL:** <https://discuss.python.org/t/access-gmail-account-via-a-local-socks5-proxy-and-delete-some-emails-based-on-specific-criterion/9787>\
**Category:** Python Help\
**Created:** [July 21, 2021, 9:17am UTC](https://discuss.python.org/t/access-gmail-account-via-a-local-socks5-proxy-and-delete-some-emails-based-on-specific-criterion/9787 "2021-07-21T09:17:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongyi-zhao](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hongyi-zhao/32/1981_2.png) [@hongyi-zhao](https://discuss.python.org/u/hongyi-zhao)\
**Post date:** [July 21, 2021, 9:17am UTC](https://discuss.python.org/t/access-gmail-account-via-a-local-socks5-proxy-and-delete-some-emails-based-on-specific-criterion/9787/1 "2021-07-21T09:17:21Z")

</div>

I want to do the following job:

1. Access my Gmail account via a local socks5 proxy running on 127.0.0.1:18888;
2. Delete some emails based on specific criterion, say, all emails whose from/to/cc/bcc fileds are not including the Gmail account itself.

Any tips for using Python to achieve this?

Regards,  
HY

---

<div class="post-metadata">

**Author:** ![tjol](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tjol/32/3414_2.png) [@tjol](https://discuss.python.org/u/tjol)\
**Post date:** [July 21, 2021, 1:49pm UTC](https://discuss.python.org/t/access-gmail-account-via-a-local-socks5-proxy-and-delete-some-emails-based-on-specific-criterion/9787/2 "2021-07-21T13:49:59Z")

</div>

The standard library contains a module to access IMAP servers, [imaplib](https://docs.python.org/3/library/imaplib.html). Alternatively, Google provide a [Gmail API](https://developers.google.com/gmail/api/quickstart/python) that may be useful.

To use a SOCKS proxy, you’ll want to use a module like [PySocks](https://pypi.org/project/PySocks/).
