Помогите
Код визуал
Код:
Unable to read data from the transport connection: The connection was closed.
Failure sending mail.
17:10:10.812 [Error] | PassRestore => EXCEPTION AT "SendEmail":
System.Net.Mail.SmtpException: Failure sending mail.
---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
at int System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(byte[] buffer, int offset, int read, bool readLine)
at LineInfo[] System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, bool oneLine)
at LineInfo System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
at void System.Net.Mail.SmtpConnection.GetConnection(string host, int port)
at void System.Net.Mail.SmtpTransport.GetConnection(string host, int port)
at void System.Net.Mail.SmtpClient.GetConnection()
at void System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at Golemo.PasswordRestore.SendEmail(Byte type, String email, Int32 textcode) in D:\golemo24April\golemo\golemo-mode-master\server\dotnet\resources\GameMode\Golemo\Main.cs:line 4309
Код визуал
Код:
public static class PasswordRestore
{
private static nLog Log = new nLog("PassRestore");
private static string mailFrom = "no-reply-night5rp@yandex.ru";
private static string mailTitle1 = "Password Restore";
private static string mailTitle2 = "New Password";
private static string mailBody1 = "<p>Код для восстановления пароля: {0}</p>";
private static string mailBody2 = "<p>Вы успешно восстановили пароль, Ваш новый пароль: {0}</p>";
private static string Server = "smtp.yandex.ru";
private static string Password = "скрыто здесь все норм";
private static int Port = 465;
public static void SendEmail(byte type, string email, int textcode)
{
try
{
MailMessage msg;
if (type == 0) msg = new MailMessage(mailFrom, email, mailTitle1, string.Format(mailBody1, textcode));
else msg = new MailMessage(mailFrom, email, mailTitle2, string.Format(mailBody2, textcode));
msg.IsBodyHtml = true;
SmtpClient smtpClient = new SmtpClient(Server, Port)
{
UseDefaultCredentials = false,
Credentials = new NetworkCredential(mailFrom, Password),
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network
};
smtpClient.Send(msg);
if (type == 0) Log.Debug($"Сообщение с кодом для восстановления пароля успешно отправлено на {email}!", nLog.Type.Success);
else Log.Debug($"Сообщение с новым паролем успешно отправлено на {email}!", nLog.Type.Success);
}
catch (Exception ex)
{
Log.Write("EXCEPTION AT \"SendEmail\":\n" + ex.ToString(), nLog.Type.Error);
}
}
}
}