C#Windows应用程序 - 带附件的自动电子邮件 [英] C# Windows Application -- Automatic Email with an Attachment
问题描述
我开发了一个窗口应用程序,用于存储员工的登录时间和注销时间。
我的表(EmpGridView)包含EmpID,cur_Date, EmpNAME,Email_ID,InTime,OutTime,Est atus,TotalWorkingHoours作为列。
现在我需要自动发送电子邮件(例如:发送到abc@abc.com)每30分钟一次。带附件。
附件包含来自EmpGridView表的详细信息,其中Estatus =''in''(这意味着我需要发送详细信息'''永远的状态是''在''而忽略所有其他)。
解释如何做到这一点。
I have developed a window application which is used to store the login time and logout time of an employee.
My table(EmpGridView)contains EmpID,cur_Date,EmpNAME,Email_ID,InTime,OutTime,Est atus,TotalWorkingHoours as the columns.
Now I need to send an email(eg: to abc@abc.com) automatically for every 30 min. with an attachment.
The attachment consists of the details from the EmpGridView table where Estatus = ''in'' (this mean I need to send the details who''s ever status is ''in'' and ignore all other).
Explain how to do this.
推荐答案
您需要 Windows服务 [ ^ ]为此。
示例:< a href =http://www.codeproject.com/KB/cs/WIndows_Service.aspx>简单的Windows服务,它发送自动电子邮件警报 [ ^ ]
有关Windows服务的详细信息: MSDN:Windows服务应用程序简介 [ ^ ]
使用C#Windows服务结合数据库电子邮件记录异步发送自动电子邮件 - 第一部分 [ ^ ]
使用C#Windows服务结合数据库电子邮件记录PART-II异步发送自动电子邮件 [ ^ ]
或者,您可以使用任务计划程序(Windows) [ ^ ]
关于任务计划程序与Windows服务 [ ^ ]
或使用 SQL Server作业 [ ^ ]
SQL数据库邮件 - 从SQL Server发送电子邮件 [ ^ ]
SQL数据库邮件 - 通过电子邮件发送T-SQL结果 [ ^ ]
BTW在CP上发现了一篇不错的文章(尼斯文章)
使用ASP.NET模拟Windows服务以运行预定作业 [ ^ ]
查看 CodeProject答案 [ ^ ]之前提出的类似问题。
对于附件,您只需在发送邮件代码中添加一行mail.Attachments.Add(attachment)
。
You need Windows Service[^] for this.
Sample: Simple Windows Service which sends auto Email alerts[^]
Details about Windows Service: MSDN: Introduction to Windows Service Applications[^]
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.
For attachment you just need to add a linemail.Attachments.Add(attachment)
in your send mail code.
这篇关于C#Windows应用程序 - 带附件的自动电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!