如何使用C#自动发送电子邮件? [英] How do you send email Automatically using C#?

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

问题描述

你好,

如何从C#自动发送电子邮件?

例如,当将新数据插入数据库时​​,我希望我的应用程序发送一封包含该数据的自动电子邮件.


或者.....

如何在设定的时间段内发送自动电子邮件,其中包含我数据库中插入,删除或修改的DATA?

有可能吗?

Hello,

How can I send an email automatically from C#?

For example, when new data is inserted into my database I want my aplication to send an automatic email containing that data.


Or.....

How do you sent an automatic email at a set period of time with the inserted, deleted or modified DATA from my database?

Is that possible?

Sorry for my english.

推荐答案

在插入过程中,电子邮件可以由数据库或应用程序代码发送.从数据库(SQL Server),如果您使用存储过程,则可以使用 xp_sendmail [ ^ ].您还可以使用不使用存储过程的插入触发器.

可以通过使用SQL作业或Windows服务来完成自动电子邮件.假定您具有确定插入,修改和删除的机制.
During insert the email can be sent either by the database or the application code. From the database (SQL Server), if you are using a stored procedure you can use xp_sendmail[^]. You can also use an insert trigger is not using a stored proc.

The automated email can be done by using a SQL Job or a Windows Service. This assumes you have a mechanism to determine insert, modified and deleted.


如何从C#自动发送电子邮件?

例如,当将新数据插入数据库时​​,我希望我的应用程序发送一封包含该数据的自动电子邮件.


也许这很容易,成功插入后您会发送电子邮件

How can I send an email automatically from C#?

For example, when new data is inserted into my database I want my aplication to send an automatic email containing that data.


maybe this is very easy, after successful insertion you send email

begin try
'' insertion code
'' after it sending mail code =)
end try
begin catch
end catch



您如何在设定的时间段内发送自动电子邮件,其中包含从我的数据库中插入,删除或修改的数据?

为此,可能有点复杂:

0),您需要了解计时器控件(此计时器 http://msdn.microsoft.com /en-us/library/system.timers.timer.aspx )

1)和Global.asax Application_Start

你做什么?您创建了一个计时器,将您的代码放入其中=)(使用计时器,您可以创建简单的计划任务),最后!在Application_Start



How do you sent an automatic email at a set period of time with the inserted, deleted or modified DATA from my database?

for this, can little complicate :

0) you need to know Timer control (this timer http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx)

1) and Global.asax Application_Start

what you do? you create a Timer put your code in it =) (with timer you can create easy scheduled tasks) and finally ouuff! start it in Application_Start


中启动它.有关如何发送电子邮件的文章-请参见这里.
For an article on how to send emails - see here.


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

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