نمایش نتایج 1 تا 2 از 2

نام تاپیک: نمونه کد دریافت ایمیل با کمی اشکال

  1. #1

    نمونه کد دریافت ایمیل با کمی اشکال

    سلام دوستان
    من این نمونه کد را برای دریافت ایمیل پیدا کردم که فکر کنم کار میده

    using System;
    using System.Net;
    using System.IO;
    using System.Text;
    using System.Xml;
    namespace Isrcomputing
    {
    class ReadingMailWebDAV
    {
    public const string strServer = ""; // Exchange server name
    public const string strPassword = ""; // Account Domain Password
    public const string strDomain = ""; // Domain
    public const string strAlias = ""; // username


    [STAThread]
    static void Main(string[] args)
    {
    System.Net.HttpWebRequest SEARCHRequest;
    System.Net.WebResponse SEARCHResponse;
    System.Net.CredentialCache MyCredentialCache;
    string strRootURI = "";
    string strQuery = "";
    byte[] bytes = null;
    System.IO.Stream SEARCHRequestStream = null;

    try
    {
    // Build the mailbox URI.
    strRootURI = "https://" + strServer + "/exchange/" + strAlias + "/Inbox/";
    MyCredentialCache = new System.Net.CredentialCache();
    MyCredentialCache.Add(new System.Uri(strRootURI),
    "NTLM",
    new System.Net.NetworkCredential(strAlias, strPassword, strDomain)
    );

    // Build the SQL query.
    strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\">"
    + "<D:sql>SELECT \"urn:schemas:httpmail:sendername\" , \"urn:schemas:httpmail:subject\","
    + " \"urn:schemas:mailheader:from\", \"urn:schemas:httpmail:datereceived\" ,"
    + " \"urn:schemas:httpmail:date\", \"urn:schemas:httpmail:textdescription\" ,"
    + " \"urn:schemas:httpmail:htmldescription\", \"DAV:id\""
    + ", \"DAV:href\""
    + " FROM \"" + strRootURI + "\""
    + " WHERE \"DAV:ishidden\" = false AND \"DAV:isfolder\" = false"
    + " </D:sql></D:searchrequest>";
    // Create a new CredentialCache object and fill it with the network
    // credentials required to access the server.
    SEARCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(s trRootURI);

    ServicePointManager.ServerCertificateValidationCal lback = delegate(object sender, System.Security.Cryptography.X509Certificates.X509 Certificate pCertificate, System.Security.Cryptography.X509Certificates.X509 Chain pChain, System.Net.Security.SslPolicyErrors pSSLPolicyErrors)
    {
    return true;
    };

    SEARCHRequest.Credentials = MyCredentialCache;
    SEARCHRequest.Method = "SEARCH";
    SEARCHRequest.ContentType = "text/xml";
    bytes = Encoding.UTF8.GetBytes((string)strQuery);
    SEARCHRequest.ContentLength = bytes.Length;
    SEARCHRequestStream = SEARCHRequest.GetRequestStream();
    SEARCHRequestStream.Write(bytes, 0, bytes.Length);
    SEARCHRequestStream.Close();

    SEARCHResponse = SEARCHRequest.GetResponse();
    System.Text.Encoding enc = System.Text.Encoding.Default;
    if (SEARCHResponse == null)
    {
    Console.WriteLine("Response returned NULL!");
    }
    Console.WriteLine(SEARCHResponse.ContentLength);
    System.IO.StreamReader sr = new System.IO.StreamReader(SEARCHResponse.GetResponseS tream(), System.Text.Encoding.ASCII);
    string sa = sr.ReadToEnd();
    sr.Close();
    SEARCHResponse.Close();

    XmlDocument doc = new XmlDocument();
    doc.InnerXml = sa;
    XmlNodeList mailId = doc.GetElementsByTagName("a:id");
    XmlNodeList mailFrom = doc.GetElementsByTagName("e:from");
    XmlNodeList mailReceivedDate = doc.GetElementsByTagName("d:datereceived");
    XmlNodeList mailSubject = doc.GetElementsByTagName("d:subject");
    XmlNodeList mailText = doc.GetElementsByTagName("d:textdescription");
    Console.WriteLine(mailId.Count);

    for (int i = 0; i < mailId.Count; ++i)
    {
    Console.WriteLine("-------------------------------\n{0}: E-mail ID: {1}", i + 1, mailId[i].InnerText);
    Console.WriteLine("From:\t{0}", mailFrom[i].InnerText);
    Console.WriteLine("Received:\t{0}", mailReceivedDate[i].InnerText);
    Console.WriteLine("Subject:\t{0}", mailSubject[i].InnerText);
    Console.WriteLine("Content:\n{0}", mailText[i].InnerText);
    }

    }
    catch (Exception ex)
    {
    // Catch any exceptions. Any error codes from the PUT
    // or MOVE method requests on the server will be caught
    // here, also.
    Console.WriteLine("Problem: {0}", ex.Message);
    }
    }
    }
    }



    حالا مثلا برای جیمیل یا یاهو موارد زیر را باید چی قرار بدم

            public const string strServer = "";      // Exchange server name
    public const string strPassword = ""; // Account Domain Password
    public const string strDomain = ""; // Domain
    public const string strAlias = ""; // username

  2. #2

    نقل قول: نمونه کد دریافت ایمیل با کمی اشکال

    ???????????????????????????????????????

تاپیک های مشابه

  1. دستورات ارسال و دریافت ایمیل
    نوشته شده توسط متین جان در بخش ASP.NET Web Forms
    پاسخ: 40
    آخرین پست: دوشنبه 16 دی 1392, 14:31 عصر
  2. دریافت ایمیل از سرور pop3 و انقیاد در یک دیتاست
    نوشته شده توسط nazaninam در بخش ASP.NET Web Forms
    پاسخ: 7
    آخرین پست: جمعه 03 خرداد 1387, 21:31 عصر
  3. مشکل این برنامه می شود رفع کرد مربوط به ارسال و دریافت ایمیل
    نوشته شده توسط spicirmkh در بخش برنامه نویسی در Delphi
    پاسخ: 1
    آخرین پست: شنبه 26 شهریور 1384, 16:00 عصر
  4. دریافت ایمیل
    نوشته شده توسط spicirmkh در بخش برنامه نویسی در Delphi
    پاسخ: 8
    آخرین پست: پنج شنبه 17 شهریور 1384, 12:27 عصر
  5. سوال : دریافت ایمیل
    نوشته شده توسط mahyar - r در بخش PHP
    پاسخ: 2
    آخرین پست: چهارشنبه 31 فروردین 1384, 16:31 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •