
private bool AuthLogin(string usrName, string password)
{
try
{
SendCommand("auth login", "334 VXNlcm5hbWU6");
SendCommand(ToBase64(usrName), "334 UGFzc3dvcmQ6");
SendCommand(ToBase64(password), "235");
return true;
}
catch(Exception ex)
{
m_err = ex;
return false;
}
}
public string ToBase64(string data)
{
System.Text.ASCIIEncodin
g Encoder = new System.Text.ASCIIEncodin
g();
return Convert.ToBase64String(Encoder.GetBytes(data));
}
private bool SendMessage(string from, string to, string subject, string message, MailFormat format)
{
try
{
SendCommand("MAIL FROM: " + from, "250");
SendCommand("RCPT TO: " + to, "250");
SendCommand("DATA", "354");
Smtp.SendData("From: " + from + "\r\n");
Smtp.SendData("To: " + to + "\r\n");
Smtp.SendData("Subject: " + subject + "\r\n");
if(format == MailFormat.Text)
Smtp.SendData("Content-Type: text/html; charset=\"ISO-8859-1\" \r\n");
Smtp.SendData("\r\n");
if(format == MailFormat.Text)
Smtp.SendData( HTMLEncode(message) + "\r\n");
else
Smtp.SendData( message + "\r\n");
SendCommand(".", "250");
return true;
}
catch(Exception ex)
{
m_err = ex;
return false;
}
}
private void SendCommand(string commmand, string OK_Response)
{
if(!Smtp.SendCommand(commmand))
throw Smtp.Err;
if(!Smtp.ResponseOK(OK_Response))
throw Smtp.Err;
}
public System.Exception Err
{
get
{
return m_err;
}
}