Solving Timeout Problem When Sending Email via Yandex (C#)
I have created a very simple console application, to show how can I send an email via Yandex SMTP with c#. SMTP settings: hostname: smtp.yandex.com.tr port: 465 But with these settings, it gives timeout error. Finally, I figure out a solution after lots of trial and error. I was able to make my code work by changing port number from 465 to 587.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace testsendmail { class Program { static void Main(string[] args) { var mailUserName = "myusername"; var mailPassword = "mypassword"; var mailSentFrom = "myusername"; // Configure the client: using (var client = new System.Net.Mail.SmtpClient("smtp.yandex.com.tr") { DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network }) { // client.Port = 465; // Gives timeout error client.Port = 587; client.UseDefaultCredentials = false; client.EnableSsl = true; // Create the credentials: var credentials = new System.Net.NetworkCredential(mailUserName, mailPassword); client.Credentials = credentials; // Create the message: var mail = new System.Net.Mail.MailMessage(mailSentFrom, emailListString) { Subject = "test message subject", Body = "test message body" }; try { client.Send(mail); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); } } } } |
… Devamını oku…Solving Timeout Problem When Sending Email via Yandex (C#)