smiley22 / S22.Imap

A free, easy-to-use and well-documented .NET library component for communicating with IMAP servers
http://smiley22.github.com/S22.Imap/Documentation/
MIT License
211 stars 115 forks source link

Inline Images #139

Open Ladimaco opened 6 years ago

Ladimaco commented 6 years ago

I am working on an application that monitors emails, and saves photos from the emails to a server.

This is working fine for emails with attached images. But am running into a problem with images sent inline.

With inline images, I am itterating through the AlternateViews instead of attachments.

It looks like the first inline image is not contained in the alternate views, but the rest are? For example, I look at the email in a mail client, and see 8 images inline. The message being pulled from the server with my software, saves that last 7 images, but doesn't see the first one at all.

Any idea how I get this first inline image out of the email to be able to save it as well?

Any help is appreciated!

-Larry

ademirMess commented 3 years ago

Hy, i'm really trying, but i can't download any. could you help me with a part of the code so i can download at least one image inline?

Ladimaco commented 3 years ago

Here is what I am using to do this...

` public void CheckMail(object source, ElapsedEventArgs e) { using (ImapClient imapClient = new ImapClient("imap.gmail.com", 993, "accountemail", "password", AuthMethod.Login, true, (RemoteCertificateValidationCallback)null)) { Console.WriteLine("We are connected!"); foreach (uint uid in imapClient.Search(SearchCondition.Unseen(), (string)null)) { MailMessage message = imapClient.GetMessage(uid, FetchOptions.Normal, true, (string)null); string subject = message.Subject; this.eventLog1.WriteEntry("Working on email with subject: " + subject, EventLogEntryType.Information, this.eventId++); if (!subject.ToUpper().Contains("special subject I am looking for")) { //Whatever you want to do if skipping this email imapClient.AddMessageFlags(uid, (string)null, new MessageFlag[1]); } else { if (message.Attachments.Count == 0 && message.AlternateViews.Count == 0) { //Whatever you want to do if processing this email imapClient.AddMessageFlags(uid, (string)null, new MessageFlag[1]); } //Code here to save the attachments.

                    imapClient.AddMessageFlags(uid, (string)null, new MessageFlag[1]);
                }
            }
            imapClient.Dispose();
        }
    }

`

Hope this helps