Click here to Skip to main content
16,004,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to extract email's inline attachments( images, links in the messagebody) using Gmail Api. I am not asking a thing about Gmail Rest Api what am I asking is how on earth could I extract mimeType images ? Here is the code, I am only showing the codes because I wanted to know let you know what I am playing around.. again please ignore Gmail Api and help me figure out parsing images from the message body.

C#
Message message = service.Users.Messages.Get(userId, messageId).Execute();
                IList<MessagePart> parts = message.Payload.Parts;
               
                foreach (MessagePart p in parts)
                {
                   // Console.WriteLine("Boooo");
                    if (p.Filename!=null && p.Filename.Length>0)
                    {
                        if (p.MimeType == "image/jpeg")
                        {
                            MessagePartBody dd = message.Payload.Body;
                           // Here , I want to get images from message body.
                        }
                     //   Console.WriteLine("Poooo ");
                        String attId = p.Body.AttachmentId;
                        if (attId != null)
                        {
                            MessagePartBody attachPart = service.Users.Messages.Attachments.Get(userId, messageId, attId).Execute();

                            byte[] data = FromBase64ForUrlString(attachPart.Data);

                            string decodedString = Encoding.UTF8.GetString(data);
                            File.WriteAllBytes(Path.Combine(outputdir, p.Filename), data);
                       //     Console.WriteLine("Coooo");
                           // Console.WriteLine(decodedString);
                        }
                    }
                    }
                    Console.WriteLine(message.Snippet + " " + message.SizeEstimate);


any help would be highly appreciated :)

best regards,
Posted

1 solution

 
Share this answer
 
Comments
JBobby 20-Sep-14 13:03pm    
thanks,I don't need that source code, mate , actually the code I posted in my question pretty much decode the images but I am having problem with multiple images. Besides Gmail uses base64Url encoding for inline images and attachments.

What I want is extracting texts and images separately from the messagebody ? Currently, I am extracting them together. any idea ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900