首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#邮件发送程序提示异常“551, delivery not allowed to non-local recipient”

2012-01-11 
C#邮件发送程序提示错误“551, delivery not allowed to non-local recipient”请问各位:我用C#写的邮件发送

C#邮件发送程序提示错误“551, delivery not allowed to non-local recipient”
请问各位:
        我用C#写的邮件发送程序,现在总是提示“551,   delivery   not   allowed   to   non-local   recipient”,请问该如何解决?兄弟用的是Socket方式,发送部分代码如下:
try
{
tc=new   TcpClient(smtpServer,25);
}
catch   (Exception   e)
{
tc.Close();
return   "network   error ";
}


ns   =   tc.GetStream();

string[]   SendBuffer;
string   SendBufferstr;

SendBuffer=new   String[4];
SendBuffer[0]= "EHLO   "   +   smtpServer   +   enter;
SendBuffer[1]= "AUTH   LOGIN "   +   enter;
SendBuffer[2]=Base64Encode( "test@test.com ")   +   enter;
SendBuffer[3]=Base64Encode( "abcd ")   +   enter;

byte[]   WriteBuffer;
WriteBuffer   =   Encoding.Default.GetBytes(SendBuffer[0]);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   one ";

}

int   StreamSize;
string   ReturnValue   =   String.Empty;
byte[]   ReadBuffer   =   new   byte[1024]   ;
try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
return   "Read   wrong   one ";
}

if   (StreamSize==0)
{
//return   "0 ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
//return   ReturnValue;
}

WriteBuffer   =   Encoding.Default.GetBytes(SendBuffer[1]);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   two ";

}

try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
return   "Read   wrong   two ";
}

if   (StreamSize==0)
{
//return   "0 ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
//return   ReturnValue;
}

WriteBuffer   =   Encoding.Default.GetBytes(SendBuffer[2]);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   three ";

}

try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
return   "Read   wrong   three ";
}

if   (StreamSize==0)
{
//return   "0 ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
//return   ReturnValue;
}

WriteBuffer   =   Encoding.Default.GetBytes(SendBuffer[3]);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   four ";

}

try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);


}
catch
{
return   "Read   wrong   four ";
}

if   (StreamSize==0)
{
//return   "0 ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
//return   ReturnValue;
}

SendBufferstr= "MAIL   FROM: < "   +   "bluehale@21cn.com "   +   "> "   +   enter;
WriteBuffer   =   Encoding.Default.GetBytes(SendBufferstr);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   four ";

}

try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
return   "Read   wrong   four ";
}

if   (StreamSize==0)
{
//                                 return   "0 ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
//return   ReturnValue;
}

SendBufferstr= "RCPT   TO: < "   +   "bluehale@emails.bjut.edu.cn "   + "> "   +   enter;
WriteBuffer   =   Encoding.Default.GetBytes(SendBufferstr);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
return   "Write   wrong   four ";

}

try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
return   "Read   wrong   RCPT ";
}

if   (StreamSize==0)
{
return   "RCPT ";
}
else
{
ReturnValue   =   Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
return   ReturnValue;
}

[解决办法]
这个可能跟邮箱服务器设置有关系
发送的参数好像能指定域 你可以尝试一下

热点排行