gmail IMAP clone mailbox: issue duplicating emails with same UID - python

I am trying to replicate a Google Apps mailbox into another Google account. I am using the IMAP library in Python.
I am able to get a unique UID for each mailbox. I could, download each message from each mailbox using thie UID.
The problem is that the unique UID is per mailbox, not per account. For example, one email may reside in two mailboxes, or have two labels. It will show up as two separate UIDs. If I download the email twice, they are no longer the same email. When one is deleted, the other will remain, etc.
Gmail has a X-GM-MSGID which gives a unique ID per the account.
At the moment, the only way I know of getting this X-GM-MSGID is by first getting the UID and requesting it's X-GM-MSGID. If the inbox has 10,000 emails, this will become a lot of requests. Is there a another way to get the X-GM-MSGID of all emails in an inbox, or even better, of all mailboxes?
I believe once I have the unique ID of each email, I can then FETCH the flags, time and content of each email and APPEND it onto the new server.

You can get multiple X-GM-MSGIDs using a bulk fetch:
FETCH 1:* X-GM-MSGID
However, there is a better approach.
Operate entirely within the All Mail folder (\AllMail from XLIST), and FETCH and STORE the X-GM-LABELS for each message.

Related

Python: Verify if e-mail does not exist safely

We have a database of over 200.000 e-mail addresses and associated contacts. I had an idea that if I could find out which e-mail addresses don't exist anymore I could inactivate those contacts, thus keeping a more up to date database. My main goal is not to validate if an e-mail exists. My main goal is to find as many non-exsitent e-mail addresses as possible.
I have based a lot of my research on these answers: How to check if an email address exists without sending an email?
I have tried the python validate_email library, but it was very unreliable. It's also unsafe because you could get banned if you try to validate multiple contacts at the same company any time. It returned False to my active company e-mail, and None to my active gmail as well... so definitely unreliable.
I have tried both DNS with py3dns and MX records. Also the VRFY command. Unfortunately none of these seemed to be reliable since any e-mail server could send a fake response.
Greylisting is also a problem:
There is also an antispam technique called greylisting, which will
cause the server to reject the address initially, expecting a real
SMTP server would attempt a re-delivery some time later. This will
mess up attempts to validate the address.
The idea also occured to my that I could send a dummy e-mail, or two because of greylisting with a bit of delay in between them. I am afraid that this could get me blacklisted after a while, especially if multiple of these contacts work at the same company. Another idea is to do this from randomly generated e-mail addresses and hosts but that is probably not possible. Is there any way I could determine if an e-mail does not exist, preferably in a way that the chance of getting banned is minimal?

Is it possible to have two mailboxes(folders) with same name?

I am working on a product where I have to interact with email servers (like zimbra, dovecot etc) through IMAP to fetch emails etc.
I am using Python's imaplib library. I connect to email server account with credentials and then select a mailbox (folder) through its name.
Now I am wondering whether is it possible to have two mailboxes with same name in an account? If yes then how to go about it ?
Question: I am probably unclear on this.
Using select(mailbox=... you are dealing with Real Folders.
Therefore no duplicate possible.
IMAP4.select(mailbox=’INBOX’, readonly=False)
Select a mailbox.
Returned data is the count of messages in mailbox (EXISTS response).
The default mailbox is 'INBOX'.
If the readonly flag is set, modifications to the mailbox are not allowed.

workaround SPAM in Catch-all email

We are building a website expecting to serve around 10k users or more.
We want a functionality that each user will have an email address # our domain, however, this email address will not be accessible by the user it will only be used to receive a very rare amount of emails (say it will be published to receive gift cards directed to that user) and we need to notify the user as any gift card is received and do something accordingly at our end
We want to use Google App Engine with Python, and what first came to our minds is that we don't actually create any real mailboxes and we create a single catch-all email that will receive any mail sent to our domain mailboxes even not existed, then we can filter all received emails and map them to our users accounts
Within current Google receive limits (1 email per second) this will work, the main issue is that SPAM mails comes and flood the catch-all mail box with emails that directly reach receive limit and email account gets suspended by Google
We want to apply a smarter solution, we only care for emails that comes from a specific sender domain (say: giftcards.com) and we can drop any other emails
Is there is any reliable service or setup at our side we can use to filter out unwanted emails and only forward emails from giftcards.com (for example) to our main Google apps email?

Choosing "From" field using python win32com outlook

I am trying to automate emails using python. Unfortunately, the network administrators at my work have blocked SMTP relay, so I cannot use that approach to send the emails (they are addressed externally).
I am therefore using win32com to automatically send these emails via outlook. This is working fine except for one thing. I want to choose the "FROM" field within my python code, but I simply cannot figure out how to do this.
Any insight would be greatly appreciated.
If you configured a separate POP3/SMTP account, set the MailItem.SendUsingAccount property to an account from the Namespace.Accounts collection.
If you are sending on behalf of an Exchange user, set the MailItem.SentOnBehalfOfName property

Fetch mails from another mailbox in Google App Engine

I am trying to fetch mails from another mailbox (xxx#domail.com or xxx#gmail.com) in google-app-engine.
I don't want to read mails from appspotmail box as it is being used for different purpose.
Is there any efficient way in which i can make this happen.
Two options:
You could read an inbox via POP/IMAP, but this requires a bit of coding. You also need to have Outgoing Sockets API enabled, which requires you to have a paid app. This approach is async, which means you will constantly need to poll for new messages.
Forward emails to a new appspotmail address (you can have many). This is pretty easy, especially since you already process incoming emails. Since you can have multiple accounts, e.g. xyz#yourappid.appspotmail.com, you can distinguish between them in code.
You can use imap+oauth to read email from a google address. If you google it the very first result is what you need. https://developers.google.com/gmail/oauth_overview

Categories