public void Send()
{
string response;
this.Connect(this.session.Sender, 25);
response = this.Response();
if (response.Substring(0, 3) != "220")
{
throw new SmtpException(response);
}
this.Write("HELO {0}\r\n", Util.GetIPAddress());
response = this.Response();
if (response.Substring(0, 3) != "250")
{
throw new SmtpException(response);
}
this.Write("MAIL FROM:<{0}>\r\n", this.session.MailFrom);
response = this.Response();
if (response.Substring(0, 3) != "250")
{
throw new SmtpException(response);
}
this.session.Recipients.ForEach(
address =>
{
this.Write("RCPT TO:<{0}>\r\n", address);
response = this.Response();
if (response.Substring(0, 3) != "250")
{
throw new SmtpException(response);
}
});
this.Write("DATA\r\n");
response = this.Response();
if (response.Substring(0, 3) != "354")
{
throw new SmtpException(response);
}
NetworkStream stream = this.GetStream();
stream.Write(this.session.Message, 0, this.session.Message.Length);
this.Write("\r\n.\r\n");
response = this.Response();
if (response.Substring(0, 3) != "250")
{
throw new SmtpException(response);
}
this.Write("QUIT\r\n");
response = this.Response();
if (response.IndexOf("221") == -1)
{
throw new SmtpException(response);
}
}