Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 22-Jun-10 4:35am
v3

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.
 
Share this answer
 
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


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
 
Share this answer
 
For an article on how to send emails - see here.
 
Share this answer
 
Comments
[no name] 22-Jun-10 11:04am    
Reason for my vote of 1
Too complicated for OP who apparently posses limited skills to begin with. Using System.Net.Mail namespace is much simpler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900