Click here to Skip to main content
16,008,490 members
Home / Discussions / C#
   

C#

 
Questionhow to change datalist's bind fied by codebehind code? Pin
BigGirlBigEyes12-Mar-04 17:04
BigGirlBigEyes12-Mar-04 17:04 
GeneralDataGrid to DataSet to XML Pin
jazzle12-Mar-04 16:04
jazzle12-Mar-04 16:04 
GeneralRe: DataGrid to DataSet to XML Pin
Mike Ellison12-Mar-04 19:07
Mike Ellison12-Mar-04 19:07 
GeneralRe: DataGrid to DataSet to XML Pin
jazzle13-Mar-04 0:53
jazzle13-Mar-04 0:53 
GeneralRe: DataGrid to DataSet to XML Pin
OmegaSupreme13-Mar-04 2:30
OmegaSupreme13-Mar-04 2:30 
GeneralRe: DataGrid to DataSet to XML Pin
jazzle13-Mar-04 3:30
jazzle13-Mar-04 3:30 
GeneralRe: DataGrid to DataSet to XML Pin
Mike Ellison15-Mar-04 8:29
Mike Ellison15-Mar-04 8:29 
Generalhelp!!! Very strange problem with sending mail Pin
wolft12-Mar-04 15:17
wolft12-Mar-04 15:17 
Confused | :confused: The following is my program of sending an email, when i debug it with F10 step by step, it seems that every thing goes right, and the receiver can receive the mail.

but when i run the program, there are always problems and the mail can't be delivered....

please help me!

Confused | :confused:

using System;
using System.Net.Sockets;
using System.IO;
using System.Text;
using System.Data;
using System.Net;

using System.Threading;

namespace MailSend
{
/// <summary>
/// MailSend &#30340;&#25688;&#35201;&#35828;&#26126;&#12290;
/// </summary>


public class MailSend : TcpClient
{
public String server;
public int port = 25;
public String username = "xxxx";
public String password = "xxxx";
public String subject = "the mail subject";
public String htmlbody = "<HTML><HEAD><TITLE>Untitled Document</TITLE></HEAD> <body> <B> blank for now</html>";
public String from = "xxx@xxx.edu.cn";
public String to = "wolft@sina.com.cn";
public String fromname = "fromme";
public String content_type = "text/html";
public String encode = "base64";
public String charset = "GB2312";

string CRLF = "\r\n";

[STAThread]
static void Main(string [] args)
{
MailSend Ms = new MailSend();
Ms.server = "smtp.sjtu.edu.cn";
Ms.to = "wolft@sina.com.cn";
Ms.getMailServer();

if (Ms.send() == true)
{
Console.WriteLine("Mail delivered succesfully!");
Ms.Dispose(true);
Console.Read();
return;
}

Console.WriteLine("Mail UNdelivered!");
Ms.Dispose(true);
Console.Read();


}


public MailSend()
{
//
// TODO: &#22312;&#27492;&#22788;&#28155;&#21152;&#26500;&#36896;&#20989;&#25968;&#36923;&#36753;
//
}

public bool send()
{
WriteStream("MAIL From: "+this.fromname+"<"+this.from+">" + CRLF);//&#21457;&#20214;&#20154;


WriteStream("RCPT To:"+this.to);//&#25910;&#20214;&#20154;



if (!OperaStream("DATA","354"))//
{

this.Close(); //&#20851;&#38381;&#36830;&#25509;
return false;
}


WriteStream("Date: "+DateTime.Now); //&#19979;&#38754;&#36825;&#21253;&#19996;&#35199;&#19968;&#23450;&#35201;&#20889;&#22312;DATA&#21518;&#38754;,&#19981;&#28982;&#23601;&#21457;&#19981;&#20986;&#21435;&#20102;.

WriteStream("Subject: "+this.subject);//&#20027;&#39064;

WriteStream("To:"+this.to);//&#25910;&#20214;&#20154;

WriteStream("Content-Type: text/html");

WriteStream(htmlbody);


WriteStream(CRLF);
if (!OperaStream(".","250"))//&#26368;&#21518;&#20889;&#23436;&#20102;&#65292;&#36755;&#20837;"."
{
WriteStream(CRLF);
this.Close(); //&#20851;&#38381;&#36830;&#25509;
return false;
}
WriteStream(CRLF);
return true;


}

private void WriteStream(String strCmd)
{
Stream TcpStream;
strCmd = strCmd + "\r\n";
TcpStream = this.GetStream();
byte [] bWrite = Encoding.GetEncoding("GB2312").GetBytes(strCmd.ToCharArray());

int start = 0;
int length = bWrite.Length;
int page = 0;
int size = 75;
int count = size;
if (length>75)
{
if((length/size)*size != length)
page = length/size + 1;
else
page = length / size;

for (int i = 0; i < page; i ++)
{
start = i * size;
if( i == page -1 )
count = length - ( i * size);
TcpStream.Write(bWrite, start, count);
}
}
else
TcpStream.Write(bWrite, 0, bWrite.Length);


}

private string ReceiveStream()
{
String sp = null;
byte [] by = new byte[1024];
NetworkStream ns = this.GetStream();
int size = ns.Read(by, 0, by.Length);

if (size>0)
{
sp = Encoding.Default.GetString(by);
}

return sp;
}

private bool OperaStream(string strCmd, string state)
{
string sp = null;
bool success = false;
try
{
WriteStream(strCmd);
sp = ReceiveStream();
if ( sp.IndexOf(state) != -1)
success = true;

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
return success;
}

private string AuthStream(String strCmd)
{
try
{
byte [] by = Encoding.Default.GetBytes(strCmd.ToCharArray());
strCmd = Convert.ToBase64String(by);
}
catch(Exception ex)
{
return ex.ToString();
}
return strCmd;
}

public bool getMailServer()
{
try
{
System.Net.IPAddress ipaddress = (IPAddress)System.Net.Dns.Resolve(this.server).AddressList.GetValue(0);
System.Net.IPEndPoint endpoint = new IPEndPoint(ipaddress, 25);
Connect(endpoint);
ReceiveStream();
if (this.username != null)
{
if (!OperaStream("HELO Localhost", "250"))
{
this.Close();
return false;
}
if (!OperaStream("EHLO Localhost", "250"))
{
this.Close();
return false;
}

if (!OperaStream("auth login", "334"))
{
this.Close();
return false;
}

username = AuthStream(username);
if(!OperaStream(this.username, "334"))
{
this.Close();
return false;
}

password = AuthStream(password);
if(!OperaStream(this.password, "235"))
{
this.Close();
return false;
}
return true;
}
else
{
if(!OperaStream("EHLO Localhost", "250"))
{
return true;
}
else
return false;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}

}
}

GeneralRe: help!!! Very strange problem with sending mail Pin
John Fisher13-Mar-04 13:30
John Fisher13-Mar-04 13:30 
GeneralINT to Binary Pin
MrEyes12-Mar-04 14:14
MrEyes12-Mar-04 14:14 
GeneralRe: INT to Binary Pin
PJL12-Mar-04 15:04
PJL12-Mar-04 15:04 
GeneralRe: INT to Binary Pin
Michael Flanakin17-Mar-04 19:36
Michael Flanakin17-Mar-04 19:36 
GeneralSomething wrong with my binding to datagird. Pin
lordjpg12-Mar-04 13:08
lordjpg12-Mar-04 13:08 
GeneralRe: Something wrong with my binding to datagird. Pin
MrEyes12-Mar-04 14:30
MrEyes12-Mar-04 14:30 
GeneralRe: Something wrong with my binding to datagird. Pin
lordjpg12-Mar-04 15:30
lordjpg12-Mar-04 15:30 
GeneralAdding an Interface to my user controls Pin
TriBoy12-Mar-04 11:05
TriBoy12-Mar-04 11:05 
GeneralRe: Adding an Interface to my user controls Pin
John Fisher12-Mar-04 11:31
John Fisher12-Mar-04 11:31 
GeneralRemoting - instantiating a wellknown type Pin
Judah Gabriel Himango12-Mar-04 9:16
sponsorJudah Gabriel Himango12-Mar-04 9:16 
GeneralRe: Remoting - instantiating a wellknown type Pin
Heath Stewart12-Mar-04 10:29
protectorHeath Stewart12-Mar-04 10:29 
GeneralRe: Remoting - instantiating a wellknown type Pin
Judah Gabriel Himango12-Mar-04 11:03
sponsorJudah Gabriel Himango12-Mar-04 11:03 
GeneralRe: Remoting - instantiating a wellknown type Pin
Heath Stewart12-Mar-04 15:42
protectorHeath Stewart12-Mar-04 15:42 
QuestionIs there actually a difference (speed gain etc) ? Pin
Andres Coder12-Mar-04 8:05
Andres Coder12-Mar-04 8:05 
AnswerRe: Is there actually a difference (speed gain etc) ? Pin
Jeff Varszegi12-Mar-04 8:29
professionalJeff Varszegi12-Mar-04 8:29 
AnswerRe: Is there actually a difference (speed gain etc) ? Pin
HAHAHA_NEXT12-Mar-04 10:08
HAHAHA_NEXT12-Mar-04 10:08 
AnswerRe: Is there actually a difference (speed gain etc) ? Pin
Adrian Stanley13-Mar-04 0:31
Adrian Stanley13-Mar-04 0:31 

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.