Вот код, который я запускаю:
try
{
var fromAddress = new MailAddress("foo@ree.com", "foo");
var toAddress = new MailAddress("test@gmail.com", String.Empty);
const string fromPassword = "password";
const string subject = "Welcome!";
const string body = "This is a test message!";
var smtp = new SmtpClient
{
Host = "mail.foo.com",
Port = 143,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
catch (Exception e)
{
Debug.WriteLine(e.InnerException.ToString());
//Add logging here.
}
Когда я пытаюсь запустить smtp.Send(message)
, выдается следующая ошибка:
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
System.FormatException: Smtp server returned an invalid response.
at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
Каковы возможные причины этогоошибка?Что я должен искать?