smtp exception “failure sending mail”

后端 未结 2 893
青春惊慌失措
青春惊慌失措 2020-12-11 18:24

I created console application for sending Email

    public static void sendEmail(string email, string body)
    {
        if (String.IsNullOrEmpty(email))
           


        
2条回答
  •  无人及你
    2020-12-11 19:08

    In my experienced using C# SMTP Client, there is a certain steps to follow in the code (see code snippet below)

    smtpClient.Host = "smtp.gmail.com";
    smtpClient.Port = 587;
    smtpClient.EnableSsl = true;
    smtpClient.UseDefaultCredentials = false;
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtpClient.Credentials = new NetworkCredential("account@gmail.com", "secretPassword");
    smtpClient.Send(mail);
    

提交回复
热议问题