Говно код уберите, и вот вам нормальный класс для отправки по почте
#region Imports
using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Text;
#endregion Imports
public class SettingMessage
{
public static void MessageSend()
{
try
{
using (MailMessage mess = new MailMessage())
{
SmtpClient client = new SmtpClient("smtp.mail.ru", Convert.ToInt32(587)){
Credentials = new NetworkCredential("email@mail.ru", "pass"),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network};
mess.From = new MailAddress("email@mail.ru");
mess.To.Add(new MailAddress("to@yandex.ru"));
mess.Subject = Environment.UserName;
mess.SubjectEncoding = Encoding.UTF8;
mess.Body = "text";
#region Add Files
try
{
mess.Attachments.Add(new Attachment(какой файл добавлять для отправки));
}
catch { }
#endregion Add Files
client.Send(mess);
mess.Dispose();
client.Dispose();
}
catch (Exception exception)
{
File.WriteAllText("error.txt", exception.ToString());
}
}
}