我只想知道,如何使一个网络应用程序,从用户接受Excel文件的输入,并每天发送电子邮件,如果excel文件有任何新的数据可用。
我是否应该使用web服务(在本地计算机上安装该服务)?然后是如何添加Upload User-Interface。或者,我应该只使用web应用程序,并且应该在该应用程序中添加web服务吗?
请给出解决这个问题的方法。
谢谢你。
发布于 2017-06-08 14:08:23
取决于您正在构建的应用程序的性质:
发布于 2017-06-08 14:30:04
不需要在用户计算机上安装。当然,您需要一个简单的Web应用程序和一个web服务器。这里有许多关于web应用程序入门的教程,下面是一些链接:
一旦您决定要使用哪种技术,您将需要所谓的SMTP服务器;通常ISP会为您提供一个,您需要向web.config添加配置,例如:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="*SMTP server IP address*" port="25" />
</smtp>
</mailSettings>
</system.net>有关如何在ASP.NET SO post中实现这一点的详细信息,请参阅此MVC。
发布于 2019-12-16 22:44:38
如果你真的想把它作为Asp.Net WebApp上的后台作业,你应该看看:
创建要发送电子邮件的作业
public class SendMailJob : IJob
{
public void Execute(IJobExecutionContext context)
{
...Do your stuff;
}
}然后将作业配置为每天执行
// define the job and tie it to our SendMailJob class
IJobDetail job = JobBuilder.Create<SendMailJob>()
.WithIdentity("job1", "group1")
.Build();
// Trigger the job to run now, and then repeat every 24 hours
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInHours(24)
.RepeatForever())
.Build();RecurringJob.AddOrUpdate(
() => YourSendMailMethod("email@email.com"),
Cron.Daily);IHostedService (仅在Asp.Net核心中)
public class SendMailHostedService : IHostedService, IDisposable
{
private readonly ILogger<SendMailHostedService> _logger;
private Timer _timer;
public SendMailHostedService(ILogger<SendMailHostedService> logger)
{
_logger = logger;
}
public Task StartAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Hosted Service running.");
_timer = new Timer(DoWork, null, TimeSpan.Zero,
TimeSpan.FromSeconds(5));
return Task.CompletedTask;
}
private void DoWork(object state)
{
//...Your stuff here
_logger.LogInformation(
"Timed Hosted Service is working. Count: {Count}", executionCount);
}
public Task StopAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Timed Hosted Service is stopping.");
_timer?.Change(Timeout.Infinite, 0);
return Task.CompletedTask;
}
public void Dispose()
{
_timer?.Dispose();
}
}在你的startup.cs类中。在configure方法中添加此方法。
services.AddHostedService<SendMailHostedService>();如果不需要将其作为后台作业托管在您的WebApp上,那么您可以创建一个Windows Service,该服务每天在您需要的时间运行。
请看这个问题:Windows service scheduling to run daily once a day at 6:00 AM
https://stackoverflow.com/questions/44427182
复制相似问题