Question

I want to send email message with smtp/imap and check for reply after a while. So I am looking for an open source library which provide an API for sending email and check for replies later.

As far as I understand, Every message already contains unique ID and I see a lot of libraries allowing to download message by ID. but none of the SMTP clients that I saw returning this ID when sending emails.

This kind of API is helpful (S22.Imap):

using (ImapClient Client = new ImapClient("imap.gmail.com", 993,
 "username", "password", AuthMethod.Login, true))
{
    uids = GetUIdsFromMyDatabase();//how can that be achieved?
    IEnumerable<MailMessage> messages = Client.GetMessages(uids);
}

But it leaves 2 questions opened:
1. Where can I get the sent message ID?
2. How can I connect between reply and its parent (sent one)?

Was it helpful?

Solution

SMTP clients can make a Message-ID themselves. They just have to be sure that the left-hand-side is sort of unique.

If the client doesn't make an ID the SMTP server will, but it will not tell the SMTP client what the ID is. One easy and safe way is to feed the message you're about to send (the entire message) through an MD5 or SHA1 hash, base64-encode the result and make an ID of the form <hash@doma.in> where hash is the base64'd hash and doma.in is the From field's domain.

The conventional way to connect replies is to use Message-ID and References. When you send a reply, you set your References to be concatenation of the original message's References and Message-ID fields.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top