using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Net.Mail; using System.Data.SqlClient; using System.Data.SqlTypes; using System.IO;
public partial class Default2 : System.Web.UI.Page { int t = 0; ArrayList email_list = new ArrayList(); int i = 0; protected void Page_Load(object sender, EventArgs e) { } public void EmailId() { t = t + 1; string UserID; string Password; SqlDataAdapter da; DataTable datatable; using (SqlConnection con = new SqlConnection("Data Source=GLASSXP;Initial Catalog=Emailer;Integrated Security=True;Pooling=False")) { SqlCommand cmd = new SqlCommand("select UserID,Password from Login where Id='" + t + "'", con); da = new SqlDataAdapter(cmd); datatable = new DataTable(); da.Fill(datatable); UserID = Convert.ToString(datatable.Rows[0]["UserID"]); Password = Convert.ToString(datatable.Rows[0]["Password"]); } } protected void btnSendEmail_Click(object sender, EventArgs e) { EmailId(); DB dB = new DB(); System.Collections.Generic.List<string> listEmailIds = dB.GetEmailID(); foreach (string email in listEmailIds) { {
MailMessage MyMailMessage = new MailMessage(); MyMailMessage.From = new MailAddress(UserID); MyMailMessage.Bcc.Add(txtMail.Text); MyMailMessage.IsBodyHtml = true; MyMailMessage.Bcc.Add(email); MyMailMessage.Body = txtbody.Text; MyMailMessage.Subject = txtsubject.Text; MyMailMessage.Priority = MailPriority.Normal; System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(UserID, Password); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587); mailClient.EnableSsl = true; mailClient.UseDefaultCredentials = false; mailClient.Credentials = mailAuthentication; mailClient.Send(MyMailMessage); try { mailClient.Send(MyMailMessage); } catch (Exception ex) {
} } errorLbl.Visible = true; errorLbl.Text = "mail sent"; } } }
|