Click here to Skip to main content
16,005,552 members
Home / Discussions / C#
   

C#

 
AnswerRe: Using Unsafe code Pin
stancrm21-Jul-08 21:14
stancrm21-Jul-08 21:14 
GeneralRe: Using Unsafe code Pin
sumit703421-Jul-08 21:36
sumit703421-Jul-08 21:36 
QuestionBitmap to ByteArray Conversion...? Pin
DeepOceans21-Jul-08 19:59
DeepOceans21-Jul-08 19:59 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
stancrm21-Jul-08 21:16
stancrm21-Jul-08 21:16 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Guffa21-Jul-08 23:50
Guffa21-Jul-08 23:50 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Anthony Mushrow22-Jul-08 0:35
professionalAnthony Mushrow22-Jul-08 0:35 
AnswerRe: Bitmap to ByteArray Conversion...? Pin
Lutosław22-Jul-08 0:40
Lutosław22-Jul-08 0:40 
Questionpop server connection Pin
kathiresanmoorthy21-Jul-08 19:35
kathiresanmoorthy21-Jul-08 19:35 
Hi I've used the following Code to read Mail from a pop server In the UI when I enter the Server name as "smtpx14.msoutlookonline.net" and username as "X" and Password as "Confindent", it says the status as "220 exsmtp014-3.exch014.msoutlook.online.net Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at mon 21 jul 08 22:29
530 5.7.0 must issue a STARTTLS command first
530 5.7.0 must issue a STARTTLS command first
530 5.7.0 must issue a STARTTLS command first "


could some one assist me in fixing this out


Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Web.Mail;

namespace POPapp
{
///
/// Summary description for Form1.
///

public class POPForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox POPServ;
private System.Windows.Forms.TextBox User;
private System.Windows.Forms.TextBox Passw;
private System.Windows.Forms.RichTextBox Message;
private System.Windows.Forms.Button ConnectBtn;
private System.Windows.Forms.Button DisconnectBtn;
private System.Windows.Forms.ListBox Status;
private System.Windows.Forms.Button RetrieveBtn;
private System.Windows.Forms.TextBox Number;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public POPForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Number = new System.Windows.Forms.TextBox();
this.Status = new System.Windows.Forms.ListBox();
this.label4 = new System.Windows.Forms.Label();
this.Message = new System.Windows.Forms.RichTextBox();
this.label6 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.ConnectBtn = new System.Windows.Forms.Button();
this.POPServ = new System.Windows.Forms.TextBox();
this.User = new System.Windows.Forms.TextBox();
this.DisconnectBtn = new System.Windows.Forms.Button();
this.Passw = new System.Windows.Forms.TextBox();
this.RetrieveBtn = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Number
//
this.Number.Location = new System.Drawing.Point(80, 296);
this.Number.Name = "Number";
this.Number.Size = new System.Drawing.Size(56, 20);
this.Number.TabIndex = 12;
this.Number.Text = "";
//
// Status
//
this.Status.Location = new System.Drawing.Point(8, 344);
this.Status.Name = "Status";
this.Status.Size = new System.Drawing.Size(392, 56);
this.Status.TabIndex = 16;
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 96);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(64, 16);
this.label4.TabIndex = 7;
this.label4.Text = "Message";
//
// Message
//
this.Message.Location = new System.Drawing.Point(8, 112);
this.Message.Name = "Message";
this.Message.Size = new System.Drawing.Size(392, 176);
this.Message.TabIndex = 6;
this.Message.Text = "";
this.Message.WordWrap = false;
//
// label6
//
this.label6.Location = new System.Drawing.Point(8, 328);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 15;
this.label6.Text = "Status";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "POP Server";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 40);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "User";
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 2;
this.label3.Text = "Password";
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 296);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 16);
this.label5.TabIndex = 11;
this.label5.Text = "Mail Number";
//
// ConnectBtn
//
this.ConnectBtn.Location = new System.Drawing.Point(328, 16);
this.ConnectBtn.Name = "ConnectBtn";
this.ConnectBtn.TabIndex = 8;
this.ConnectBtn.Text = "Connect";
this.ConnectBtn.Click += new System.EventHandler(this.ConnectBtn_Click);
//
// POPServ
//
this.POPServ.Location = new System.Drawing.Point(80, 16);
this.POPServ.Name = "POPServ";
this.POPServ.Size = new System.Drawing.Size(224, 20);
this.POPServ.TabIndex = 3;
this.POPServ.Text = "pop.server.com";
//
// User
//
this.User.Location = new System.Drawing.Point(80, 40);
this.User.Name = "User";
this.User.Size = new System.Drawing.Size(224, 20);
this.User.TabIndex = 4;
this.User.Text = "user";
//
// DisconnectBtn
//
this.DisconnectBtn.Enabled = false;
this.DisconnectBtn.Location = new System.Drawing.Point(328, 48);
this.DisconnectBtn.Name = "DisconnectBtn";
this.DisconnectBtn.TabIndex = 9;
this.DisconnectBtn.Text = "Disconnect";
this.DisconnectBtn.Click += new System.EventHandler(this.DisconnectBtn_Click);
//
// Passw
//
this.Passw.Location = new System.Drawing.Point(80, 64);
this.Passw.Name = "Passw";
this.Passw.PasswordChar = '*';
this.Passw.Size = new System.Drawing.Size(224, 20);
this.Passw.TabIndex = 5;
this.Passw.Text = "password";
//
// RetrieveBtn
//
this.RetrieveBtn.Enabled = false;
this.RetrieveBtn.Location = new System.Drawing.Point(152, 296);
this.RetrieveBtn.Name = "RetrieveBtn";
this.RetrieveBtn.TabIndex = 10;
this.RetrieveBtn.Text = "Retrieve";
this.RetrieveBtn.Click += new System.EventHandler(this.RetrieveBtn_Click);
//
// POPForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(408, 405);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.Status,
this.label6,
this.Number,
this.label5,
this.RetrieveBtn,
this.DisconnectBtn,
this.ConnectBtn,
this.label4,
this.Message,
this.Passw,
this.User,
this.POPServ,
this.label3,
this.label2,
this.label1});
this.MaximizeBox = false;
this.Name = "POPForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Download Mail via POP3";
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new POPForm());
}

private void ConnectBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

// create server POP3 with port 110
Server = new TcpClient(POPServ.Text,25);
Status.Items.Clear();

try
{
// initialization
NetStrm = Server.GetStream();
RdStrm = new StreamReader(Server.GetStream());
Status.Items.Add(RdStrm.ReadLine());

// Login Process
Data = "USER " + User.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());

Data = "PASS " + Passw.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());

// Send STAT command to get information ie: number of mail and size
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());

// change enabled - disabled button
ConnectBtn.Enabled = false;
DisconnectBtn.Enabled = true;
RetrieveBtn.Enabled = true;

// back to normal cursor
Cursor.Current = cr;

}
catch (InvalidOperationException err)
{
Status.Items.Add("Error: " + err.ToString());
MessageBox.Show(err.Message);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}


private void DisconnectBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

// Send QUIT command to close session from POP server
Data = "QUIT"+CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
Status.Items.Add(RdStrm.ReadLine());

//close connection
NetStrm.Close();
RdStrm.Close();

// change enabled - disabled button
ConnectBtn.Enabled = true;
DisconnectBtn.Enabled = false;
RetrieveBtn.Enabled = false;

// back to normal cursor
Cursor.Current = cr;
}

private void RetrieveBtn_Click(object sender, System.EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string szTemp;
Message.Clear();
try
{
// retrieve mail with number mail parameter
Data = "RETR "+ Number.Text+CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);

szTemp = RdStrm.ReadLine();
if(szTemp[0]!='-')
{

while(szTemp!=".")
{
Message.Text += szTemp+CRLF;
szTemp = RdStrm.ReadLine();
}
}
else
{
Status.Items.Add(szTemp);
}

// back to normal cursor
Cursor.Current = cr;

}
catch(InvalidOperationException err)
{
Status.Items.Add("Error: "+err.ToString());
}

}
public TcpClient Server;
public NetworkStream NetStrm;
public StreamReader RdStrm;
public string Data;
public byte[] szData;
public string CRLF = "\r\n";
}
}

Thanks in Advance.......
Regards,
Kathir
RantRe: pop server connection Pin
Guffa21-Jul-08 23:52
Guffa21-Jul-08 23:52 
Questionretreving the gridview row in color from sqlserver using boundfields Pin
santosh04221-Jul-08 18:53
santosh04221-Jul-08 18:53 
AnswerRe: retreving the gridview row in color from sqlserver using boundfields Pin
Srishti Mathur21-Jul-08 19:48
Srishti Mathur21-Jul-08 19:48 
Questionhow to get domain part from URL Pin
George_George21-Jul-08 17:22
George_George21-Jul-08 17:22 
AnswerRe: how to get domain part from URL Pin
Bert delaVega21-Jul-08 17:40
Bert delaVega21-Jul-08 17:40 
GeneralRe: how to get domain part from URL Pin
George_George21-Jul-08 18:14
George_George21-Jul-08 18:14 
AnswerRe: how to get domain part from URL Pin
N a v a n e e t h21-Jul-08 17:59
N a v a n e e t h21-Jul-08 17:59 
GeneralRe: how to get domain part from URL Pin
George_George21-Jul-08 19:16
George_George21-Jul-08 19:16 
QuestionHow to retrieve top 10 elements in a Dictionary Pin
George_George21-Jul-08 17:11
George_George21-Jul-08 17:11 
AnswerRe: How to retrieve top 10 elements in a Dictionary Pin
N a v a n e e t h21-Jul-08 18:03
N a v a n e e t h21-Jul-08 18:03 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
George_George21-Jul-08 19:21
George_George21-Jul-08 19:21 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
Guffa21-Jul-08 21:19
Guffa21-Jul-08 21:19 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
George_George21-Jul-08 21:34
George_George21-Jul-08 21:34 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
Guffa21-Jul-08 23:54
Guffa21-Jul-08 23:54 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
George_George22-Jul-08 0:09
George_George22-Jul-08 0:09 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
Guffa22-Jul-08 2:18
Guffa22-Jul-08 2:18 
GeneralRe: How to retrieve top 10 elements in a Dictionary Pin
George_George27-Jul-08 1:33
George_George27-Jul-08 1:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.