关于C#中的流行邮件应用程序 [英] about pop mail application in c#

查看:65
本文介绍了关于C#中的流行邮件应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我在C#中制作了一个访问电子邮件的应用程序.我得到的问题是,如果用户没有收到任何新电子邮件,并且我为该用户反复运行一个应用程序,那么它会显示其第一封邮件,但我想显示一个空白文本盒.

我该怎么做.
请帮帮我.

在此先感谢.

问候,
维萨夫迪普·戈亚尔

这是我的代码

Hello,
I made a application in c# which accessing email.The problem i am getting is if the user did not get any new email and i run a application again and again for the user then it show its first mail but i want to show a blank text box.

How can i do this.
Please help me.

Thanks in Advance.

Regards,
Vishavdeep Goyal

this is my code

string curpath = Directory.GetCurrentDirectory();
string mailbox = String.Format("{0}\\inbox", curpath);
// If the folder is not existed, create it.
if (!Directory.Exists(mailbox))
{
    Directory.CreateDirectory(mailbox);
}
MailServer oServer = new MailServer(textBox4.Text,
           textBox5.Text, textBox6.Text, ServerProtocol.Pop3);
MailClient oClient = new MailClient("TryIt");
oServer.SSLConnection = true;
oServer.Port = 995;
 try
{

    oClient.Connect(oServer);
    MailInfo[] infos = oClient.GetMailInfos();
    for (int a = 0; a < 1; a++)
    {
        MailInfo info = infos[a];
        //Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
         //   info.Index, info.Size, info.UIDL);
        // Receive email from POP3 server
        Mail oMail = oClient.GetMail(info);
          string str = oMail.TextBody.ToString();
        String st = str;
        textBox7.Text = st;
        Stream stm = tcpclnt.GetStream();
        ASCIIEncoding asen = new ASCIIEncoding();
        byte[] ba = asen.GetBytes(st);
        Console.WriteLine("Transmitting.....");
        stm.Write(ba, 0, ba.Length);
        byte[] bb = new byte[100];
        int k = stm.Read(bb, 0, 100);
        for (int j = 0; j < k; j++)
            Console.Write(Convert.ToChar(bb[j]));
        tcpclnt.Close();
        System.Threading.Thread.Sleep(10000);


        // Console.WriteLine(str);
        //Console.WriteLine("Text: {0}", oMail.TextBody);
        // Generate an email file name based on date time.
        System.DateTime d = System.DateTime.Now;
        System.Globalization.CultureInfo cur = new
            System.Globalization.CultureInfo("en-US");
        string sdate = d.ToString("yyyyMMddHHmmss", cur);
        string fileName = String.Format("{0}\\{1}{2}{3}.eml",
            mailbox, sdate, d.Millisecond.ToString("d3"), a);
        // Save email to local disk
        oMail.SaveAs("email", true);
        // Mark email as deleted from POP3 server.
        oClient.Delete(info);
    }
    // Quit and pure emails marked as deleted from POP3 server.
    oClient.Quit();
}
catch (Exception ep)
{
    MessageBox.Show(ep.Message);
}
string curpath = Directory.GetCurrentDirectory();
string mailbox = String.Format("{0}\\inbox", curpath);
// If the folder is not existed, create it.
if (!Directory.Exists(mailbox))
{
    Directory.CreateDirectory(mailbox);
}
MailServer oServer = new MailServer(textBox4.Text,
           textBox5.Text, textBox6.Text, ServerProtocol.Pop3);
MailClient oClient = new MailClient("TryIt");
oServer.SSLConnection = true;
oServer.Port = 995;
 try
{

    oClient.Connect(oServer);
    MailInfo[] infos = oClient.GetMailInfos();
    for (int a = 0; a < 1; a++)
    {
        MailInfo info = infos[a];
        //Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
         //   info.Index, info.Size, info.UIDL);
        // Receive email from POP3 server
        Mail oMail = oClient.GetMail(info);
          string str = oMail.TextBody.ToString();
        String st = str;
        textBox7.Text = st;
        Stream stm = tcpclnt.GetStream();
        ASCIIEncoding asen = new ASCIIEncoding();
        byte[] ba = asen.GetBytes(st);
        Console.WriteLine("Transmitting.....");
        stm.Write(ba, 0, ba.Length);
        byte[] bb = new byte[100];
        int k = stm.Read(bb, 0, 100);
        for (int j = 0; j < k; j++)
            Console.Write(Convert.ToChar(bb[j]));
        tcpclnt.Close();
        System.Threading.Thread.Sleep(10000);


        // Console.WriteLine(str);
        //Console.WriteLine("Text: {0}", oMail.TextBody);
        // Generate an email file name based on date time.
        System.DateTime d = System.DateTime.Now;
        System.Globalization.CultureInfo cur = new
            System.Globalization.CultureInfo("en-US");
        string sdate = d.ToString("yyyyMMddHHmmss", cur);
        string fileName = String.Format("{0}\\{1}{2}{3}.eml",
            mailbox, sdate, d.Millisecond.ToString("d3"), a);
        // Save email to local disk
        oMail.SaveAs("email", true);
        // Mark email as deleted from POP3 server.
        oClient.Delete(info);
    }
    // Quit and pure emails marked as deleted from POP3 server.
    oClient.Quit();
}
catch (Exception ep)
{
    MessageBox.Show(ep.Message);
}

推荐答案

您修复了代码,以使其显示正确的内容.不知道还有什么要说的.当您不发布任何代码而只告诉我们您要执行的代码时,您期望得到什么样的答案?我什至不知道如何诊断为什么您的代码为什么不看它,或者您在哪里显示邮件并想显示文本框.
You fix the code so that it shows the right thing. Not sure what else to say. What sort of answer were you expecting, when you post no code and just tell us what you wnat your code to do ? I don''t know how to even diagnose why your code is doing that without seeing it, or where you''re showing mail and want to show a textbox.


这篇关于关于C#中的流行邮件应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆