C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...







Automatically Sending Email from Sql Table Through Windows Services


Posted Date: 19 Jul 2008    Resource Type: Code Snippets    Category: Windows Services

Posted By: Selva Eswar       Member Level: Bronze
Rating:     Points: 8



Here is the windows services Code sample for automatically sending emails from your sql table.

The example uses a Timer to fire the event automatically. The mail is sent when time elapses.


public System.Timers.Timer timer1;
protected override void OnStart(string[] args)
{

timer1.Enabled = true;
timer1.Start();

}

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
SendEmail();

}


public void SendEmail()
{

conn = new SqlConnection(@"Server=;UID=sa;pwd=sa;Database=");
conn.Open();
da = new SqlDataAdapter("select top 1 * from tbl_mail where status=0 order by MailIn_DT", conn);
ds = new DataSet();
da.Fill(ds);

if (ds != null)
{
DataRow dr = ds.Tables[0].Rows[0];
string MailTo = dr["To_Mail"].ToString();
string MailSubject = dr["Subject"].ToString();
string MailMessage = dr["Message"].ToString();

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.urs.com");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("Userid", "Password");
client.EnableSsl = true;
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage("Userid", MailTo, MailSubject, MailMessage);
Mail.IsBodyHtml = true;

client.Send(Mail);
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Send Email with Windows Services  .  Send Email from Table with Windows Services  .  Send Email from SQL Table with Windows Services  .  Send Email automatically with Windows Services  .  Automatic Email Sending  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: This C# code snippet obtains the NetBIOS and DNS computer names of the local computer
Return to Discussion Resource Index
Post New Resource
Category: Windows Services


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use