How do I avoid a delay when sending email from my application?

前端 未结 6 962
深忆病人
深忆病人 2021-01-26 03:23

I have a small console application. It checks a few settings, makes some decisions, and sends an email. The problem is the email doesn\'t actually get sent until my application

6条回答
  •  萌比男神i
    2021-01-26 04:10

    Simply dispose the MailMessage and SmtpClient objects after the .Send() function.

    SmtpClient smtpClient = new SmtpClient("server", 25);
    smtpClient.UseDefaultCredentials = true;
    
    MailMessage message = new MailMessage("ToAddress","FromAddress");
    message.Subject = "Test email";
    message.Body = "Test email";
    
    smtpClient.Send(message);
    
    message.Dispose();
    smtpClient.Dispose();
    

提交回复
热议问题