Reputation: 528
I want to read from my gmail , I want to search for the email subject("subject"), it includes in it an attachment (photo) , I want to get the photo as Image and use it .
I tried to use MailRepository class, from here : http://mailsystem.codeplex.com/
but it reads all the emails in my gmail ,and the program stucks.
I need an effective way for my purpose ,
thanx in advance
Upvotes: 1
Views: 370
Reputation: 528
I found out how to achieve that :
First of all , one needs to add reference called : OpenPop
public static byte[] GetUserImage(string image_name)
{
Pop3Client c = new Pop3Client();
c.Connect("pop.gmail.com", 995, true);
c.Authenticate("your gmail", "password");
for (int i = c.GetMessageCount(); i >= 1; i--)
{
OpenPop.Mime.Message mess = c.GetMessage(i);
if (mess.Headers.Subject.Equals(image_name))
{
return mess.MessagePart.MessageParts[1].Body;//this to get attachment
**OR:**
return Encoding.ASCII.GetString(mess.MessagePart.Body);//this to get text
}
}
return null ;
}
Upvotes: 2