Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

What is wrong with the code?!

Posted on 2009-07-01
6
Medium Priority
?
365 Views
Last Modified: 2013-12-17

Hello group,

I'm just new to C# and found a code on CodeProject to pool some emails from a mail server. The code is a class so I'm adding a project and using it.

However, I get errors as:

Error      1      Using the generic type 'System.Collections.Generic.IEnumerator<T>' requires '1' type arguments      C:\downloads\WindowsFormsApplication1\Form1.cs      43      25      WindowsFormsApplication1

Error      2      'Pop3.Pop3Component' does not contain a definition for 'Body' and no extension method 'Body' accepting a first argument of type 'Pop3.Pop3Component' could be found (are you missing a using directive or an assembly reference?)      C:\downloads\WindowsFormsApplication1\Form1.cs      51      43      WindowsFormsApplication1


How can I fix them?



Thanks,
ak

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pop3;
 
 
 
 
namespace WindowsFormsApplication1
{
    
 
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            
            string s_username = "user1@domain.com";
            string s_password = "passwd";
            string s_pop3_server = "mail.domain.com";
 
 
            try
            {
                Pop3Client email = new Pop3Client(s_username, s_password, s_pop3_server);
                email.OpenInbox();
 
                while (email.NextEmail())
                {
                    if (email.IsMultipart)
                    {
                        IEnumerator enumerator = email.MultipartEnumerator;
                        while (enumerator.MoveNext())
                        {
                            Pop3Component multipart = (Pop3Component)
                            enumerator.Current;
                            if (multipart.IsBody)
                            {
                                Console.WriteLine("Multipart body:" +
                                multipart.Body);
                            }
                            else
                            {
                                Console.WriteLine("Attachment name=" +
                                multipart.Name); // ... etc
 
                            }
                        }
                    }
                }
 
                email.CloseConnection();
 
            }
            catch (Pop3LoginException)
            {
                Console.WriteLine("You seem to have a problem logging in!");
            }
 
            
        }
    }
}

Open in new window

0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24759601
be sure to have:
using System.Collections;
along with
using System.Collections.Generic;
0
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 2000 total points
ID: 24760639
This is the best solution of the your problem, you might need to change your code and use the new class.

Refer to :
http://www.developerfusion.com/article/4071/how-to-pop3-in-c/
0
 
LVL 16

Expert Comment

by:sunithnair
ID: 24761762
Try the code like this
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 16

Expert Comment

by:sunithnair
ID: 24761764

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pop3;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            string s_username = "user1@domain.com";
            string s_password = "passwd";
            string s_pop3_server = "mail.domain.com";
 
            try
            {
                Pop3Client email = new Pop3Client(s_username, s_password, s_pop3_server);
                email.OpenInbox();
                while (email.NextEmail())
                {
                    if (email.IsMultipart)
                    {
                        IEnumerator enumerator = email.MultipartEnumerator;
                        while (enumerator.MoveNext())
                        {
                            Pop3Component multipart = (Pop3Component)
                            enumerator.Current;
                            if (multipart.IsBody)
                            {
                                Console.WriteLine("Multipart body:" +
                                multipart.Data);
                            }
                            else
                            {
                                Console.WriteLine("Attachment name=" +
                                multipart.Name); // ... etc
 
                            }
                        }
                    }
                }
                email.CloseConnection();
            }
            catch (Pop3LoginException)
            {
                Console.WriteLine("You seem to have a problem logging in!");
            }
        }
    }
}

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24762416
I think it is just a matter of the missing namespace.
0
 

Author Closing Comment

by:akohan
ID: 31599029
Thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question