Remove Duplicate of bulk email received from different user - c#

i have five user using outlook email client. Each of them receiving mails from a email marketing. i need to get all the unique mails from all my five user. i used the following,
Message-ID of outlook email header.
if a same mail received to same user, then Message-ID is same. so that i can able to eliminate the duplicate mails.
if a same mail received to different user, then Message-ID is not same. so that i can able to eliminate the duplicate mails.
is there any better way to eliminate the duplicate mail from different user

As far as I know the message ID is exactly what you cannot use. It is always different. Check the properties of the emails and find similarities and check these. The first is going to be the From then Subject then maybe a part of the body.

Related

EWS: Retrieving more than just attachments from signed emails

I am trying to create a system that will intercept emails coming into various email addresses and catalogue them, along with all of their attachments. These attachments are all files that we need to load into another system. Currently, we are using Outlook Macros to drop all of the attachments to a directory and load them that way. Unfortunately, this method does not lend itself easily to tracking which emails had which attachments. If we want to ensure we are accounting for every document we have received, we need a more robust approach.
So, I am building an EWS-based Windows service. The idea is that it will subscribe to all of the email addresses that I want to manage. So, it will know about all new emails, catalogue them, and track the attachments. It works well for most emails, but emails sent securely need to be viewed by a person (as those emails require a log-in to a secure server somewhere to view the message and download attachments). But, digitally signed emails, I just wind up downloading an attachment named 'smime.p7m'. I found a post on this forum that shows me how to grab the attachments, but what about if the email body is digitally signed? Is there a way I could extract that, as well?
I decided to go with the MimeKit approach described here (it is not the accepted answer, but several of the answers deal with MimeKit, so I decided to check it out, and it looks promising).
My current approach is, if the email body was not digitally signed, then I can load that into my system directly from the base email. But, if it is digitally signed, then I need to grab it from the smime.p7m file, and that is where I am running into trouble. I have no problem using the examples to extract the attachments, though. Currently, I have no examples of a digitally signed email body. But, I would like to be proactive and find a solution before it does happen and a user asks why the email body is missing. Alternately, it would be equally helpful to know if this is not possible, and the only portion of an email that gets digitally signed would be the attachments (in which case, I can ignore this completely). That would actually be the best case scenario!
Generally, when a message is signed via S/MIME, the entire message (including the body and attachments) are signed.
Theoretically, it is possible for each individual component of the message to be signed individually, but that's not how most mail clients work (I don't know of any that do anything other than signing the entire message).
If you want to make sure to handle any scenario, just make sure to handle all MultipartSigned parts and/or ApplicationPkcs7Mime parts within the message and then you'll be sure to handle all scenarios (in other words, don't assume there is only ever 1 of those).

linking a received email with a sent email

I have just completed reading received and sent emails using c# console application well that was easy part now the problem is I wanted to know is there a way of linking a received email to its replied/sent email like lets say i create a streamwriter and I write the contents that I need from the received email and the contents from the replied/sent email. How would I then go about knowing the received email to its replied/sent email? How would I link them? Uniquely differentiate from the tons of email?

Reading Unique mails using gmail API

I am reading mails using Gmail API, where I could successfully download the mails to my system. The idea is to navigate through all the label and download the mails, but that is resulting in duplicate mail downloading, as a single mail can belong to different label.
I tried looking up for label $All to get unique mails but i guess All Mail Label is not supported in latest Gmail API. Is there a way to read unique mails in gmail?
Synchronizing the mailbox can be done using Gmail Synchronization guide:
https://developers.google.com/gmail/api/guides/sync
Use history.list() method of Gmail API with Label ID filter and check for 'messagesAdded' section for Message IDs. You will not get the message body, only IDs, and subsequently have to call message.get() with received Message IDs to get message body.
If a message has multiple labels, history.list() will give you messages directly received in a particular label, hence you will not get the same message twice if you call history.list() with different label IDs.
You can also avoid duplicate messages by handling them in your application by storing each message ID in a cache store such as memcache or an in-memory hash table to avoid processing duplicate messages.

SendGrid Parse API and SaaS app

I would like to add the ability for users to send an email to an address that automatically saves the attachments as documents and saves the email as html, etc.
I think I understand how I can write the functions, but I'm uncertain on how to ensure the security. My application is designed as single code, but each customer has their own database and subdomain. The app looks at the subdomain and determines the database to use for authentication, etc. (There is no master db.)
First, I thought sendgrid would give you a custom email address to use like a897a88s8#sendgrid.net that you could forward to for testing or real use but I don't see that anywhere. I would probably set up a separate domain
How do I ensure that emails sent from user from companyA gets saved in their db? I've thought of:
putting the company name in the email address that the user sends to "addpart-companyA#mysaasapp.com"
a custom email address with a company-wide unique key "addpart-3515645#mysaasapp.com"
The code can find the right db, look at the 'from' email address to see if it matches an existing user, then perform the desired functions. However, that doesn't seem too secure. I also am going to want several different email addresses that a user can use that performs different functions ('add to existing part, add to new part, don't add document, etc.)
I'm looking for a better setup that preferably allows for non-ugly email addresses. What do others do?
It sounds like you already have subdomains for each company. Are these used for email at all right now, or can you change the MX records for the subdomains? If you can programmatically alter your DNS, then it would be very easy to add a SendGrid parse MX record for each subdomain when it is created. Then you could use addpart#company.mysaasapp.com.
For security, I think you're on the right track with checking against a user in your database. Assuming your clients have their email properly configured, you could check SPF via the Authentication-Results header if you are concerned about spoofs.

How to thread emails using custom headers?

Does gmail preserve x-headers in email replies?
I'm developing an application which threads emails and email replies together using a Thread Id.
I add the header through SMTP .net library with the thread id, using the key X-ThreadId.
If I send it to a gmail account, I can see the header in there in the email source. However if I then reply to it, I want that header to be sent in the reply. It seems to drop that particular header.
Does gmail drop header information in the reply email? Is this a generic problem with email? If so, how do I get round this problem?
I can confirm that Gmail does not add X- headers to the new email when you hit reply button.

Categories