Advertisement
Advertisement
| 04.04.2008 at 01:55PM PDT, ID: 23297412 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: |
protected void btnsubmit_Click(object sender, EventArgs e)
{
string toemail = null;
MailMessage ebatch = new MailMessage();
SmtpClient mySmtpClient = null;
OleDbConnection DBConnection = null;
OleDbCommand DBCommand = null;
OleDbDataReader Datareader = null;
string SQLString = null;
DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/App_Data/cust.mdb"));
DBConnection.Open();
SQLString = "SELECT EmailID FROM Customers ";
DBCommand = new OleDbCommand(SQLString, DBConnection);
Datareader = DBCommand.ExecuteReader();
while (Datareader.Read())
{
toemail = Convert.ToString(Datareader["EmailID"]);
ebatch.From = new MailAddress("confirmation@testsite.com");
ebatch.To.Add(toemail);
ebatch.Subject = "sample message";
ebatch.Body = "this is a test message";
// mail server//
mySmtpClient = new SmtpClient(ConfigurationManager.AppSettings["SmtpRelay"]);
mySmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mySmtpClient.UseDefaultCredentials = true;
try
{
mySmtpClient.Send(ebatch);
Response.Write("<i> Email Sent to " + toemail + "!</i>");
System.Threading.Thread.Sleep(1000);
}
catch (Exception ex)
{
Response.Write("the following exception occurred:" + ex.ToString());
// check with InnerException
while (ex.InnerException != null)
{
Response.Write("--------------");
Response.Write("the following InnerException reported:" + ex.InnerException.ToString());
ex = ex.InnerException;
}
}
}
Datareader.Close();
DBConnection.Close();
}
|