Ciao a tutti, ho realizzato una piccola applicazione che funziona tramite socket e che riesce a collegarsi tramite telnet.
Il problema ora è che quando faccio una prova di invio mail, riesco ad arrivare fino all'invio del comando data.
Per chi non mastica molto l'invio di mail tramite telnet, ecco una piccola guida.
Una volta che mi è comparso "Start mail input; end with <CRLF>.<CRLF>" e provo a scrivere il testo per poi inviare il comando, non succede nulla. L'applicazione non entra nemmeno nel metodo Page Load(), avreste qualche idea? Posto i due metodi più importanti.S: telnet nomeserver 25
R: 220 qualcheparte Simple Mail Transfer Service Ready
S: HELO miohost
R: 250 miohost
S: MAIL FROM:<Marco@miohost>
R: 250 OK
S: RCPT TO:<Roberto@suohost>
R: 250 OK
S: DATA
R: 354 Start mail input; end with <CRLF>.<CRLF>
Codice PHP:public string Read()
{
string OutputValue = "";
int c = 0;
while (true)
{
try
{
if (this._networkStream.DataAvailable)
{
while (this._networkStream.DataAvailable)
{
this._receivedBuffer = new byte[0x400];
c = this._networkStream.Read(this._receivedBuffer, 0, this._receivedBuffer.Length);
OutputValue = OutputValue + Encoding.ASCII.GetString(this._receivedBuffer, 0, c);
}
return OutputValue;
}
Thread.Sleep(500);
}
catch (Exception ex)
{
return ex.Message;
}
}
}
public void Send(string command)
{
string c = command.Replace("\n", br);
byte[] msg = Encoding.ASCII.GetBytes(c+br);
if (_networkStream.CanWrite)
{
this._networkStream.Write(msg, 0, msg.Length);
this._networkStream.Flush();
}
}

Rispondi quotando