- Регистрация
- 08.09.2010
- Сообщения
- 576
- Благодарностей
- 41
- Баллы
- 28
C#:
var fromEmailString = "[email protected]";
var toEmailString = "[email protected]";
var login = "[email protected]";
var password = "Choxoxoxo";
var server = "poczta.interia.pl";
int port;
int.TryParse("465", out port);
bool encryptConnection;
bool.TryParse("encryptedConnection", out encryptConnection);
var messageText = "Hey";
var messageSubject = "I just wanted t2o let you know that Monica and I were going to go play some paintball, you in?";
// Формирование реквизитов письма
var fromAddress = new System.Net.Mail.MailAddress(fromEmailString, fromEmailString);
var toAddress = new System.Net.Mail.MailAddress(toEmailString, toEmailString);
// создаем подключение к почтовому серверу
var smtp = new System.Net.Mail.SmtpClient
{
Host = server,
Port = port,
EnableSsl = encryptConnection,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(login, password)
};
// создаем письмо
var message = new System.Net.Mail.MailMessage(fromAddress, toAddress)
{
Subject = messageSubject,
Body = messageText,
IsBodyHtml = false,
};
try
{
smtp.Send(message);
project.SendInfoToLog ("Отправил");
}
catch
{
project.SendInfoToLog ("нЕ ОТПРАВЛЕНО");
}
message.Dispose();