即使关闭页面也要调用C#函数. [英] calling a C # function even when the page is closed.

查看:50
本文介绍了即使关闭页面也要调用C#函数.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,
亲爱的朋友,我建立了一个网站,希望在午夜时分,即使没有人登录,也要每天向所有会员发送保险提醒邮件.

因此没有人调用提醒功能.应该在每个午夜定期进行.

预先感谢,
Rajkumar

please help,
dear friends i have developed a website in which i want to send a insurance reminders Email every day to all members , in the midnight even when no one is logged in the website.

so no one is calling the reminder function. it should be done periodically at every midnight.

Thanks in advance,
Rajkumar

推荐答案

您是否已准备好发送电子邮件的SMTP代码?如果没有,请访问我的答案.

在此之前,请执行以下操作:
1.创建一个控制台应用程序.
2.编写代码以获取假定接收这些电子邮件的所有用户的电子邮件列表. (您可以在其中提供过滤od用户.)
3.添加此代码以发送电子邮件
Do you have your SMTP code ready for sending email ? if NO then visit my this answer .

Before that do these:
1. Create a console application.
2. Write a code to fetch list of emails of all the user which are suppose to recieve those email. (in this you can provide filteration od users.)
3. Add this code to send email
protected void SendMail()
{
    // Gmail Address from where you send the mail
    var fromAddress = "Gmail@gmail.com";
    // any address where the email will be sending
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address
    const string fromPassword = "Password";
     // Passing the values and make a email formate to display
    string subject = YourSubject.Text.ToString();
    string body = "From: " + YourName.Text + "\n";
    body += "Email: " + YourEmail.Text + "\n";
    body += "Subject: " + YourSubject.Text + "\n";
    body += "Question: \n" + Comments.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com"; // provide your smtpserver
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
// provide your stmp server credentials
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}


4.全面测试.
5.以发布模式进行构建.
6.从bin文件夹中获取exe并将其添加到服务器的Schedule TASK中
7.如果您不知道该怎么做,请参阅:.. 安排任务 [ ^ ]

8.如果发现它对您有用,请不要忘记将其标记为答案


4. Test it throughly.
5. build it in release mode.
6. Take the exe from your bin folder and add that into Schedule TASK of your server
7. If you dont know how to do it refer this : ..Schedule a Task[^]

8. Dont forget to mark it as answer if you have found it working for you


这篇关于即使关闭页面也要调用C#函数.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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