I want to email my users in the database and I want to begin my mail body Mr or Mrs using the users' names in the database. But I was unsuccessful in this codes. What is the wrong in this codes?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
Konu:
</td>
<td>
<asp:TextBox ID="txtkonu" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Mesaj:
</td>
<td>
<asp:TextBox ID="txtmesaj" TextMode="MultiLine" Width="300px" Height="150px" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" Text="Gönder" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Label ID="lblmesaj" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Net.Mail;
using System.Net;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string isim = string.Empty;
string soyisim = string.Empty;
OleDbConnection cnn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath(@"App_Data\MailDB.mdb"));
OleDbCommand bulten = new OleDbCommand("Select isim,soyisim, mail from Mailler where MailId", cnn);
if (ConnectionState.Closed == cnn.State)
cnn.Open();
OleDbDataReader bdr = bulten.ExecuteReader();
while (bdr.Read())
{
isim = bdr["isim"].ToString();
soyisim = bdr["soyisim"].ToString();
}
MailMessage ePosta = new MailMessage();
ePosta.From = new MailAddress("xxxx@xxxx.com");
//ePosta.To.Add (bdr["mail"].ToString());
ePosta.Subject = txtkonu.Text;
ePosta.Body = string.Format("{0} {1}<br/><br/>{2}<br/><br/>", isim, soyisim, txtmesaj.Text);
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("xxxx@xxxxx.com", "password");
smtp.Port = 587;
smtp.Host = "mail.gmail.com";
while (bdr.Read())
{
ePosta.Bcc.Add(bdr["Mail"].ToString());
smtp.Send(ePosta);
}
bdr.Close();
cnn.Close();
lblmesaj.ForeColor = Color.Green;
lblmesaj.Text = "E-Postalar Başarıyla Gönderildi";
}
}