Home c# Sending messages to C # mail does not work

Sending messages to C # mail does not work

Author

Date

Category

Hello, tell me how to send a message to the mail from your Mail.ru account

Known smtp-server smtp.mail.ru

Known port 465

Here is the code

SmtpClient client = new SmtpClient ("smtp.mail.ru", 465);
client.Credentials = new NetworkCredential ("[email protected]", "password");
MailMessage message = new MailMessage ();
message.To.Add (email);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.GetEncoding ("windows-1251");
message.IsBodyHtml = true;
message.From = new MailAddress ("[email protected]");
message.Subject = "Subject";
message.Body = "YOU WIN A MILLION";
client.Send (message);

But it doesn’t work, why? (sending to Yandex)


Answer 1, authority 100%

Here is the working code that sends the email:

MailMessage mail = new MailMessage ();
mail.From = new MailAddress ("[email protected]"); // Sender address
mail.To.Add (new MailAddress ("[email protected]")); // Address of the recipient
mail.Subject = "Title";
mail.Body = "Letter ........................";
SmtpClient client = new SmtpClient ();
client.Host = "smtp.mail.ru";
client.Port = 587; // Note that port 587
client.EnableSsl = true;
client.Credentials = new NetworkCredential ("[email protected]", "password"); // Your username and password
client.Send (mail);

Answer 2, authority 100%

Try adding:

client.EnableSsl = true;

Answer 3

To send from mail.ru to mail.ru in .Net Core, you can use the following code:

SmtpClient client = new SmtpClient ();
  client.UseDefaultCredentials = false;
  client.Port = 25;
  client.EnableSsl = true;
  client.DeliveryFormat = SmtpDeliveryFormat.International;
  client.DeliveryMethod = SmtpDeliveryMethod.Network;
  client.Host = "smtp.mail.ru";
  client.Timeout = 300000;
  client.Credentials = new NetworkCredential ("[email protected]", "frompassword");
  MailMessage mailMessage = new MailMessage ();
  mailMessage.From = new MailAddress ("[email protected]");
  mailMessage.To.Add ("[email protected]");
  mailMessage.Body = "Markup";
  mailMessage.Subject = "Title";
  mailMessage.BodyEncoding = System.Text.Encoding.UTF8;
  mailMessage.BodyTransferEncoding = System.Net.Mime.TransferEncoding.Base64;
  mailMessage.IsBodyHtml = true;
  mailMessage.Priority = MailPriority.Normal;
  mailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
  client.Send (mailMessage);
  client.Dispose ();

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions