public void 正常系(InetKind inetKind, SmtpClientAuthKind kind) { //setUp var sut = CreateSmtpClient(inetKind); //exercise Assert.That(sut.Connect(), Is.EqualTo(true)); Assert.That(sut.Helo(), Is.EqualTo(true)); Assert.That(sut.Auth(kind, "user1", "user1"), Is.EqualTo(true)); Assert.That(sut.Mail("1@1"), Is.EqualTo(true)); Assert.That(sut.Rcpt("*****@*****.**"), Is.EqualTo(true)); Assert.That(sut.Data(new Mail()), Is.EqualTo(true)); Assert.That(sut.Quit(), Is.EqualTo(true)); //tearDown sut.Dispose(); }
public void 正常系(InetKind inetKind, SmtpClientAuthKind kind) { //setUp var sut = CreateSmtpClient(inetKind); //exercise Assert.That(sut.Connect(), Is.EqualTo(true)); Assert.That(sut.Helo(), Is.EqualTo(true)); Assert.That(sut.Auth(kind, "user1", "user1"), Is.EqualTo(true)); Assert.That(sut.Mail("1@1"), Is.EqualTo(true)); Assert.That(sut.Rcpt("*****@*****.**"), Is.EqualTo(true)); Assert.That(sut.Data(new Mail()), Is.EqualTo(true)); Assert.That(sut.Quit(), Is.EqualTo(true)); //tearDown sut.Dispose(); }
public bool Auth(SmtpClientAuthKind kind,String user, String pass) { //トランザクションでない場合エラー if (Status != SmtpClientStatus.Transaction) { SetLastError("Auth() Status != Transaction"); return false; } //AUTH送信 var authStr=""; switch (kind){ case SmtpClientAuthKind.Login: authStr = "AUTH LOGIN"; break; case SmtpClientAuthKind.Plain: authStr = "AUTH PLAIN"; break; case SmtpClientAuthKind.CramMd5: authStr = "AUTH CRAM-MD5"; break; } if (!SendCmd(authStr)){ return false; } //334受信 if (!RecvStatus(334)){ return false; } //ユーザ・パスワード送信 switch (kind){ case SmtpClientAuthKind.Plain: //ユーザ名送信 var str = String.Format("{0}\0{1}\0{2}", user, user, pass); if (!SendCmd(String.Format(Base64.Encode(str)))) { return false; } break; case SmtpClientAuthKind.Login: //ユーザ名送信 if (!SendCmd(String.Format(Base64.Encode(user)))) { return false; } //334受信 if (!RecvStatus(334)) { return false; } //パスワード送信 if (!SendCmd(String.Format(Base64.Encode(pass)))) { return false; } break; case SmtpClientAuthKind.CramMd5: //MD5送信 var timestamp = _recvStr.Split(' ')[1]; var s = string.Format("{0} {1}", user, Md5.Hash(pass, Base64.Decode(timestamp))); if (!SendCmd(Base64.Encode(s))) { return false; } break; } //235受信 if (!RecvStatus(235)) { return false; } Status = SmtpClientStatus.Transaction; return true; }
public bool Auth(SmtpClientAuthKind kind, String user, String pass) { //トランザクションでない場合エラー if (Status != SmtpClientStatus.Transaction) { SetLastError("Auth() Status != Transaction"); return(false); } //AUTH送信 var authStr = ""; switch (kind) { case SmtpClientAuthKind.Login: authStr = "AUTH LOGIN"; break; case SmtpClientAuthKind.Plain: authStr = "AUTH PLAIN"; break; case SmtpClientAuthKind.CramMd5: authStr = "AUTH CRAM-MD5"; break; } if (!SendCmd(authStr)) { return(false); } //334受信 if (!RecvStatus(334)) { return(false); } //ユーザ・パスワード送信 switch (kind) { case SmtpClientAuthKind.Plain: //ユーザ名送信 var str = String.Format("{0}\0{1}\0{2}", user, user, pass); if (!SendCmd(String.Format(Base64.Encode(str)))) { return(false); } break; case SmtpClientAuthKind.Login: //ユーザ名送信 if (!SendCmd(String.Format(Base64.Encode(user)))) { return(false); } //334受信 if (!RecvStatus(334)) { return(false); } //パスワード送信 if (!SendCmd(String.Format(Base64.Encode(pass)))) { return(false); } break; case SmtpClientAuthKind.CramMd5: //MD5送信 var timestamp = _recvStr.Split(' ')[1]; var s = string.Format("{0} {1}", user, Md5.Hash(pass, Base64.Decode(timestamp))); if (!SendCmd(Base64.Encode(s))) { return(false); } break; } //235受信 if (!RecvStatus(235)) { return(false); } Status = SmtpClientStatus.Transaction; return(true); }