自动发送电子邮件... [英] Automatically sending emails...

查看:101
本文介绍了自动发送电子邮件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我有一个网站。我认为我的网站可以发布电子邮件。所以,我希望电子邮件的代码每天自动发送给所有注册用户,而不使用任何安装文件。用户可以选择某些日期或周或月。然后用户选择的日期只有那天电子邮件可以从我的网站转发我怎么能这样做。请帮助我.....







谢谢...

hi...
i have a website. i think my website can be publishes with email.so, i want code for emails automatically sends daily to all registered users with out using any setup file. and user can choose certain dates or weeks or months. then what user selected dates only that days emails can be forward from my website how can i do this.please help me.....



thank you...

推荐答案

Windows服务 [ ^ ]是最好的选择。

参考更多信息: http://msdn.microsoft。 com / en-us / library / d56de412(VS.80).aspx [ ^ ]



使用C#Windows服务异步发送自动电子邮件数据库电子邮件记录 - 第一部分 [ ^ ]

Sendin g使用C#Windows服务与数据库电子邮件记录PART-II异步异步自动发送电子邮件 [ ^ ]



或者,您可以使用任务计划程序( Windows) [ ^ ]

关于的比较任务计划程序与Windows服务 [ ^ ]



或使用 SQL Server工作 [ ^ ]

SQL数据库邮件 - 从SQL Server发送电子邮件 [ ^ ]

SQL数据库邮件 - 通过电子邮件发送T-SQL结果 [ ^ ]



BTW在CP中发现了一篇不错的文章(尼斯文章)

使用ASP.NET模拟Windows服务以运行预定作业 [<小时ef =http://www.codeproject.com/KB/aspnet/ASPNETService.aspxtarget =_ blanktitle =新窗口> ^ ]



查看 CodeProject Answers [ ^ ]对于之前提出的类似问题。
Windows Service[^] is the best choice.
Refer more: http://msdn.microsoft.com/en-us/library/d56de412(VS.80).aspx[^]

Sending Automated Emails asynchronously using a C# Windows Service in conjunction with Database Email records – Part I[^]
Sending Automated Emails asynchronously using a C# Windows Service in conjunction with Database Email records PART – II[^]

Alternatively, you may use Task Scheduler (Windows)[^]
A comparison about Task Scheduler vs Windows Service[^]

Or use SQL Server jobs[^]
SQL Database Mail - Send Emails from SQL Server[^]
SQL Database Mail - Send T-SQL Results by Email[^]

BTW found a nice article in CP(Nice article)
Simulate a Windows Service using ASP.NET to run scheduled jobs[^]

Check out CodeProject Answers[^] for similar question asked before.


在您的应用程序中包含Quartz.NET的最简单方法是通过Nuget。您可以通过在Package Manager Console提示符下键入Install-Package Quartz,或者在Visual Studio的Solution Explorer中右键单击项目并选择Manage Nuget Packages来实现此目的。





The easiest way to include Quartz.NET in your application is via Nuget. You can do this either by typing Install-Package Quartz at the Package Manager Console prompt or by right clicking on the project in Visual Studio's Solution Explorer and selecting Manage Nuget Packages.


Quartz consists of 3 primary components - a job, a trigger and a scheduler





创造要执行的工作





Creating Job to Perform

using Quartz;
using System;
using System.Net;
using System.Net.Mail;

namespace ScheduledTaskExample.ScheduledTasks
{
    public class EmailJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            using (var message = new MailMessage("user@gmail.com", "user@live.co.uk"))
            {
                message.Subject = "Test";
                message.Body = "Test at " + DateTime.Now;
                using (SmtpClient client = new SmtpClient
                {
                    EnableSsl = true,
                    Host = "smtp.gmail.com",
                    Port = 587,
                    Credentials = new NetworkCredential("user@gmail.com", "password")
                })
                {
                    client.Send(message);
                }
            }
        }
    }
}





设置调度程序和触发器





Setting Up Scheduler and Trigger

using Quartz;
using Quartz.Impl;
using System;

namespace ScheduledTaskExample.ScheduledTasks
{
    public class JobScheduler
    {
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();

            IJobDetail job = JobBuilder.Create<EmailJob>().Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInHours(24)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
                  )
                .Build();

            scheduler.ScheduleJob(job, trigger);
        }
    }
}





希望这有帮助!



Hope this Helps!


参考



http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx [ ^ ]



这个一个人收集了很多样本​​

http:// archive .msdn.microsoft.com / nclsamples / Wiki / View.aspx?title = Mailer [ ^ ]


这篇关于自动发送电子邮件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆