如何激活课程?

时间:2019-01-09 17:35:17

标签: asp.net-mvc asp.net-mvc-5 visual-studio-2017

我使用的时间跨度将测试电子邮件发送到我的电子邮件,但是当我启动系统时,在定义的时间内它什么都没发给我。

我为此建立了模型:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Threading.Tasks;
using System.Web;
using System.Web.Configuration;

namespace macpartner.Models.NonFunctional
{


    public class EmailAviso
    {


        private static MailMessage mail = new MailMessage();
        private static readonly SmtpClient SmtpServer = new SmtpClient("smtp.umbler.com");
        public static void SendEmailTeste()
        {

            var startTimeSpan = TimeSpan.Zero;
            var periodTimeSpan = TimeSpan.FromMinutes(1);

            var timer = new System.Threading.Timer((e) =>
            {
                if ((DateTime.Now.TimeOfDay >= System.TimeSpan.Parse("14:14:00.000") && DateTime.Now.TimeOfDay <= System.TimeSpan.Parse("14:22:00.000"))
                || (DateTime.Now.TimeOfDay >= System.TimeSpan.Parse("16:00:00.000") && DateTime.Now.TimeOfDay <= System.TimeSpan.Parse("16:10:00.000")))
                {
                    mail = new MailMessage();

                    mail.Subject = "MacPartner - Teste Aviso";
                    mail.From = new MailAddress("macpartner@macpartner.com.br");
                    mail.To.Add("wesleyhenri.mac@gmail.com");
                    mail.IsBodyHtml = true;
                    SmtpServer.Port = 587;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("macpartner@macpartner.com.br", "M@cP@rtner");
                    SmtpServer.EnableSsl = true;



                    mail.Body = "Olá confirmação de email";



                    SmtpServer.Send(mail);
                }
            },
                          null, startTimeSpan, periodTimeSpan);
        }

    }

}

要激活该课程我该怎么做?

我只需要在服务器上激活该类,而不必在进入任何计算机的所有计算机上激活该类。

0 个答案:

没有答案