시스템 사용;
system.text 사용;
System.io 사용;
System.net 사용;
System.net.sockets 사용;
네임 스페이스 blood.com.classlib
{
/// <요약>
/// tcpclient 派生类 派生类, 用来进行 smtp 服务器的连接工作
/// </summary>
공개 수업 smtpclient : tcpclient
{
공개 bool isconnected ()
{
활성화 된 반품;
}
public void sendcommandToserver (String 명령)
{
NetworkStream ns = this.getStream ();
바이트 [] 쓰기 버퍼;
WriteBuffer = 새로운 바이트 [1024];
WriteBuffer = encoding.default.getBytes (명령);
ns.Write (WriteBuffer, 0, writeBuffer.length);
반품;
}
공개 문자열 getServerResponse ()
{
int 스트림 크기;
문자열 returnValue =;
바이트 [] readbuffer;
NetworkStream ns = this.getStream ();
readbuffer = 새로운 바이트 [1024];
StreamSize = ns.Read (ReadBuffer, 0, ReadBuffer.length);
if (streamSize == 0)
{
return returnValue;
}
또 다른
{
returnValue = encoding.default.getString (readBuffer);
returnReturnValue;
}
}
public bool doesstringcontainsmtpcode (String s, String smtpcode)
{
return (s.indexof (smtpcode, 0,10) ==-1)? 거짓 : true;
}
} // 结束类
/// <요약>
/// 发送邮件类
/// </summary>
공개 클래스 smtpmail
{
/// <요약>
/// 错误反馈信息
/// </summary>
개인 문자열 strerrmessage = null;
/// <요약>
/// smtp sm
/// </summary>
개인 문자열 strrrrsponse;
/// <요약>
/// 构造函数
/// </summary>
공개 smtpmail ()
{
strerrmessage =;
strrrresponse =;
}
/// <요약>
/// 取得错误反馈信息
/// </summary>
공개 문자열 errormessage
{
얻다
{
Strerrmessage를 반환하십시오.
}
}
/// <요약>
/// t smtp 服务器反馈的信息
/// </summary>
공개 문자열 ServerResponse
{
얻다
{
strrrroponse를 반환합니다.
}
}
/// <요약>
/// 邮件发送优先级
/// </summary>
공개 열거 우선 순위
{
/// <요약>
/// 最高级别
/// </summary>
높음 = 1,
/// <요약>
/// 默认级别
/// </summary>
정상 = 3,
/// <요약>
/// 最低级别
/// </summary>
낮음 = 5
}
public void sendmail (String smtphost, int port, string from, string displayfromname, String to, String displaytoname, 우선 순위 우선 순위, bool html, String base, string subject, string message)
{
노력하다
{
문자열 strrREPONSENUMBER;
smtpclient smtpcmail = new smtpclient ();
smtpcmail.connect (smtphost, port);
bool bolconnect = smtpcmail.isconnected ();
// 判断是否进行了连接
if (! bolconnect)
{
strerrmessage = smtp 服务器连接失败 ...;
반품;
}
// 读取反馈信息
strrReponsEnumber = smtpcmail.getServerResponse ();
if (smtpcmail.doestringcontainsmtpcode (strrresponsenumber, 220))
{
this.StrResponse += strrREPONSENUMBER;
}
또 다른
{
this.strerRmessage = 连接失败 + strrrponsenumber;
반품 ;
}
문자열 [] strsendbuffer = 새 문자열 [6];
String [] strrponsecode = {220,250,251,354,221}; // SMTP 서버의 성공 코드
문자열 strdata =;
strdata = string.concat (Helo, smtphost);
strdata = string.concat (strdata,/r/n);
strsendbuffer [0] = strdata;
strdata =;
strdata = string.concat (메일 :, < + from +>);
strdata = string.concat (strdata,/r/n);
Strsendbuffer [1] = strdata;
strdata =;
strdata = string.concat (rcpt to :, < + to +>);
strdata = string.concat (strdata,/r/n);
Strsendbuffer [2] = strdata;
strdata =;
strdata = string.concat (data,/r/n);
Strsendbuffer [3] = strdata;
strdata =;
strdata = string.concat (from :, displayfromname + < + from +>);
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, to :);
strdata = string.concat (strdata, displaytoname + < + to +>);
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, 제목 :);
strdata = string.concat (strdata, subject);
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, 마임 버전 : 1.0);
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, x-priority : + 우선 순위);
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, x-msmail-priority : + 우선 순위);
strdata = string.concat (strdata,/r/n);
if (html == true)
{
strdata = string.concat (strdata, 내용-유형 : text/html;);
}
또 다른
{
strdata = string.concat (strdata, 컨텐츠 유형 : 텍스트/일반;);
}
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, charset =/ iso-8859-1/);
strdata = string.concat (strdata,/r/n);
if (html == true)
{
strdata = string.concat (strdata, content-transfer-encoding : text/html;);
}
또 다른
{
strdata = string.concat (strdata, content-transfer-encoding : text/plain;);
}
strdata = string.concat (strdata,/r/n);
strdata = string.concat (strdata, content-base : / + base + /);
strdata = string.concat (strdata,/r/n +/r/n);
strdata = string.concat (strdata, message);
strdata = string.concat (strdata,/r/n./r/n);
Strsendbuffer [4] = strdata;
strdata =;
strdata = string.concat (strdata, quit/r/n);
Strsendbuffer [5] = strdata;
int i = 0;
while (i <strsendbuffer.length)
{
smtpcmail.sendcommandtoserver (strsendbuffer [i]);
strrReponsEnumber = smtpcmail.getServerResponse ();
for (int j = 0; j <strresponsecode.length; j ++)
{
if (smtpcmail.doesstringContainsmtpcode (strrresponsenumber, strrponsecode [j]))
{
this.StrResponse += strrREPONSENUMBER;
this.strresponse += <br>;
부서지다;
}
또 다른
{
if (j == strrrsponsecode.length-1)
{
this.strerrmessage += strrrponsenumber;
this.strerrmessage += strsendbuffer [i];
반품;
}
}
}
i ++;
} // 结束循环
}
CATCH (PocketException err)
{
this.strerRmessage + = err.message + + err.stacktrace;
}
캐치 (예외 E)
{
this.strerrmessage + = e.message + + e.stacktrace;
}
} // 结束邮件发送方法
} // 结束类
} // 结束 네임 스페이스