我如何告诉我的申请发送电子邮件?

时间:2022-07-30 07:21:11

How would I tell my application to send an email to a subscriber? How would I send it every week starting from the time the appication is launched.

我如何通知我的申请向订户发送电子邮件?我该如何从appication开始每周发送它。

3 个解决方案

#1


8  

Use the classes in the System.Net.Mail namespace to send emails from your app. Specifically, the MailMessage class serves this purpose.

使用System.Net中的类。邮件名称空间用于从应用程序发送电子邮件。

To send emails periodically, you can use a timer (use System.Timers.Timer, for example) or you could use the built-in Windows task scheduler, which has rich functionality and runs as a service, so that you don't need to keep an interactive session open on your machine. I can give you a more detailed answer if you provide more details about the type of app you're developing.

要定期发送电子邮件,可以使用计时器(使用system . timer)。例如,计时器)或者您可以使用内置的Windows任务调度程序,它具有丰富的功能并作为服务运行,因此您不需要在您的机器上保持交互式会话的打开。我可以给你一个更详细的答案,如果你提供更多关于你正在开发的应用程序类型的细节。

#2


0  

I haven't created anything directly like this myself but I've seen solutions that use a Scheduled Task on the Server which are set to run on a certain date/time a small script that carries out what is required. This assumes you have your own server though...

我自己还没有直接创建任何类似的东西,但是我看到了一些解决方案,它们使用服务器上的一个计划任务,该任务设置为在特定的日期/时间运行一个执行所需的小脚本。假设您有自己的服务器…

#3


0  

I use this method to use gmail, and it works well for me.

我使用这个方法来使用gmail,它对我来说很有用。

var fromAddress = new MailAddress("From");
                var toAddress = new MailAddress("To");
                string fromPassword = textBox4.Text;
                const string subject = "Test";
                const string body = "Test Finished";

                var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    Attachment attachf = new Attachment("C:\\file.txt");
                    message.Attachments.Add(attachf);
                    smtp.Send(message);
                }
            }

#1


8  

Use the classes in the System.Net.Mail namespace to send emails from your app. Specifically, the MailMessage class serves this purpose.

使用System.Net中的类。邮件名称空间用于从应用程序发送电子邮件。

To send emails periodically, you can use a timer (use System.Timers.Timer, for example) or you could use the built-in Windows task scheduler, which has rich functionality and runs as a service, so that you don't need to keep an interactive session open on your machine. I can give you a more detailed answer if you provide more details about the type of app you're developing.

要定期发送电子邮件,可以使用计时器(使用system . timer)。例如,计时器)或者您可以使用内置的Windows任务调度程序,它具有丰富的功能并作为服务运行,因此您不需要在您的机器上保持交互式会话的打开。我可以给你一个更详细的答案,如果你提供更多关于你正在开发的应用程序类型的细节。

#2


0  

I haven't created anything directly like this myself but I've seen solutions that use a Scheduled Task on the Server which are set to run on a certain date/time a small script that carries out what is required. This assumes you have your own server though...

我自己还没有直接创建任何类似的东西,但是我看到了一些解决方案,它们使用服务器上的一个计划任务,该任务设置为在特定的日期/时间运行一个执行所需的小脚本。假设您有自己的服务器…

#3


0  

I use this method to use gmail, and it works well for me.

我使用这个方法来使用gmail,它对我来说很有用。

var fromAddress = new MailAddress("From");
                var toAddress = new MailAddress("To");
                string fromPassword = textBox4.Text;
                const string subject = "Test";
                const string body = "Test Finished";

                var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    Attachment attachf = new Attachment("C:\\file.txt");
                    message.Attachments.Add(attachf);
                    smtp.Send(message);
                }
            }