Код: Выделить всё
using System.Net.Mail;
namespace PasswordManager
{
public partial class Form1 : Form
{
Random rnd = new();
private void SendVerificationCode(object sender, EventArgs e)
{
if (!(textBox4.Text == "") && !(textBox2.Text == ""))
{
verificationCode = "";
for (int _ = 0; _ < 4; _++)
{
verificationCode += nums[rnd.Next(0, 10)];
}
try
{
MailMessage mail = new MailMessage();
SmtpClient smtp = new SmtpClient();
mail.From = new MailAddress("**********@gmail.com");
mail.To.Add(textBox2.Text);
mail.Subject = "Verification code";
mail.Body = verificationCode;
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("*********@gmail.com", "**********");
smtp.EnableSsl = true;
smtp.Send(mail);
}
catch (Exception)
{
throw new Exception("It's not working");
}
}
}
}
}
Он выдает исключение «это не работает".
Может ли кто-нибудь мне помочь?
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/790 ... m-net-mail