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

前端 未结 6 914
深忆病人
深忆病人 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条回答
  •  佛祖请我去吃肉
    2021-01-26 04:12

    you should use a SMTP client. do it like this:

                MailMessage mm = new MailMessage();
                //fill in your message
                NetworkCredential nc = new NetworkCredential(FromAddress, FromPassword);
                SmtpClient sc = new SmtpClient(SmtpHost, SmtpPort);
                sc.EnableSsl = true;
                sc.Credentials = nc;
                sc.Send(mm);
    

    at this stage your mail will be sent.

    But, sending an email is an async act, so it will take some time until you recive the mail.

提交回复
热议问题