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


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Automatically send emails to the emailid from the database


Posted Date: 06 Oct 2008      Total Responses: 2

Posted By: jeya sakthi vel murugan       Member Level: Bronze     Points: 1


How to send email to the email id in the database for the selected criteria?
Thanks in advance




Responses

Author: divya    07 Oct 2008Member Level: GoldRating:     Points: 2
Try the following .This is a sample code to send mail to selected members from database.

Public Sub ProcessEmailHistory()
Dim gen As New Genfun()
Dim jobid, type As String
Dim dr As SqlDataReader = dbfun.selectspecifiedfields("siteactivity", "jid,jtype", "activityid!=0")
While dr.Read()
jobid = dr(0)
type = dr(1)
If type = "Job" Then
Dim dr1 As SqlDataReader = selectspecifiedfields("tldtemp", "professionid", "jobid='" & jobid & "'")
While dr1.Read()
Dim profsn As String = dr1(0)
Dim dr2 As SqlDataReader = selectspecifiedfields("tldtemp", "tempid", "professionid=" & profsn & "")
While dr2.Read()
If dr2(0).ToString = "" Then
Else
Dim jobseekerid As String = dr2(0)
Dim fname As String = gen.Find("tldregistration", "firstname", "regnid='" & jobid & "'")
Dim lname As String = gen.Find("tldregistration", "lastname", "regnid='" & jobid & "'")
mailJob(jobseekerid, jobid, fname, lname)
InsertAll("emailhistory", "'" & jobid & "','" & jobseekerid & "'")
delete("siteactivity", "jid='" & jobid & "'")
' WebMsgBox.Show("Mail send to " & fname & "")
Response.Write("Mail send to " & fname & " " & " -" & " &" & jobid & "")
End If

End While
End While
ElseIf type = "Jobseeker" Then
Dim dr1 As SqlDataReader = selectspecifiedfields("tldtemp", "professionid", "tempid='" & jobid & "'")
While dr1.Read()
Dim profsn As String = dr1(0)
Dim dr2 As SqlDataReader = selectspecifiedfields("tldtemp", "jobid", "professionid=" & profsn & " and jobid is NOT NULL")
While dr2.Read()
If dr2(0).ToString = "" Then
Else
Dim fname As String = gen.Find("tldregistration", "firstname", "regnid='" & jobid & "'")
Dim lname As String = gen.Find("tldregistration", "lastname", "regnid='" & jobid & "'")
mailJob(jobid, dr2(0), fname, lname)
InsertAll("emailhistory", "'" & dr2(0) & "','" & jobid & "'")
delete("siteactivity", "jid='" & jobid & "'")

'WebMsgBox.Show("Mail send to " & fname & "")
Response.Write("Mail send to " & fname & " " & " -" & " &" & dr2(0) & "")
End If


End While

End While

End If
End While
WebMsgBox.Show("Completed")
End Sub
Private Sub mailJob(ByVal jobseekerid As String, ByVal jobid As String, ByVal fname As String, ByVal lname As String)

Dim Mail As New MailMessage()
Dim gen As New Genfun()
Dim ActiveBody As New StringBuilder()
Dim message As New MailMessage()
Dim mailto As String = gen.Find("tldregistration", "mailid", "regnid='" & jobseekerid & "'")
message.To.Add(mailto)
message.From = New MailAddress(" DoNotReply@tldmechanical.com")
message.Subject = "Hello" + " " & fname & ""
message.Subject = "TLD Online Registration"
Dim link As String = "http://extolution.ath.cx/tldMech/ViewDetailsNew.aspx?id=" & jobid & "&"
message.Body = "Hello" + " " & fname & " " + "" + "" & lname & "" + " < br > " + "Thank you for showing interest in TLDMechanical." + " <br> " + "Click the link to see matching jobs." + " <br> " + link
message.IsBodyHtml = True
''SMTP..SmtpServer = ConfigurationSettings.AppSettings("SmtpServer");
SMTP.Send(message)


End Sub


Public Function selectspecifiedfields(ByVal tablename As String, ByVal fields As String, ByVal condition As String)
Dim connection As String = getConnection()
Dim con As New SqlConnection(connection)
con.Open()
Dim qry As String = "select " + fields + " from " + tablename + " where " + condition + ""
Dim cmd As New SqlCommand(qry, con)
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
End Function
'To insert all fields to a table.

Public Sub InsertAll(ByVal tablename As String, ByVal fieldvalues As String)
Dim connection As String = getConnection()
Dim con As New SqlConnection(connection)
con.Open()
Dim qry As String = "insert into " + tablename + " values(" + fieldvalues + ")"
Dim cmd As New SqlCommand(qry, con)
cmd.ExecuteNonQuery()
End Sub
'To delete data from a table.

Public Sub delete(ByVal tablename As String, Optional ByVal condition As String = "")
Dim connection As String = getConnection()
Dim con As New SqlConnection(connection)
con.Open()
Dim qry As String
If condition = "" Then
qry = "delete from " + tablename + " "
Else
qry = "delete from " + tablename + " where " + condition + ""
End If

Dim cmd As New SqlCommand(qry, con)
cmd.ExecuteNonQuery()
End Sub


Author: Athira Appukuttan    07 Oct 2008Member Level: DiamondRating:     Points: 2
Try like this
//Here SQLHelp is one class file.from there am getting connectiona and also included some commomn functions.

using System.Net.Mail;
SQLHelper OldEmp = new SQLHelper();
SqlDataReader OldEmployee = OldEmp.ExecuteReader("select * from Ms_Candidate where id='" + Session["EmpId"] +"'");
while (OldEmployee.Read())
{
if( OldEmployee["Email"].ToString())
{
MailMessage m_newmail = new MailMessage();
SmtpClient s_client = new SmtpClient();
m_newmail.To.Add(OldEmployee["Email"].ToString());

MailAddress fromAdr = new MailAddress(admin@admin.com);
m_newmail.From = fromAdr;
m_newmail.Subject = "About employee's address status ";
m_newmail.Body = Empname + " has been changed " + sGender + " Correspondance / Permanent Address";
m_newmail.IsBodyHtml = true;
s_client.Host = "localhost";
s_client.UseDefaultCredentials = true;
s_client.Send(m_newmail);

ClientScript.RegisterClientScriptBlock(this.GetType(), "Hi!", String.Format("alert('An email has successfully been sent to {0}');", m_newmail.To), true);
m_newmail.Dispose();


}
}


Post Reply
You must Sign In to post a response.
Next : converting dataview to dataset in .net2003
Previous : Menu
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use